[dotnet] Set a default RuntimeIdentifier and validate that we get a valid RuntimeIdentifier. Fixes #10861.
Also add tests: * Remove RuntimeIdentifier from a few sample projects. These projects should continue to build just fine. * Add tests for invalid RuntimeIdentifiers. Fixes https://github.com/xamarin/xamarin-macios/issues/10861.
This commit is contained in:
Родитель
5955cd1c92
Коммит
724d0fe1b3
|
@ -29,6 +29,31 @@
|
|||
<TargetArchitectures Condition=" '$(_PlatformName)' != 'macOS' And '$(MtouchArch)' != '' ">$(MtouchArch)</TargetArchitectures>
|
||||
</PropertyGroup>
|
||||
<!-- If the old-style variables aren't set, figure it out using RuntimeIdentifier. -->
|
||||
<!-- First set the default RuntimeIdentifier if not already specified. -->
|
||||
<PropertyGroup Condition=" '$(RuntimeIdentifier)' == '' And '$(RuntimeIdentifiers)' == '' ">
|
||||
<RuntimeIdentifier Condition="'$(_PlatformName)' == 'iOS'">iossimulator-x64</RuntimeIdentifier>
|
||||
<RuntimeIdentifier Condition="'$(_PlatformName)' == 'tvOS'">tvossimulator-x64</RuntimeIdentifier>
|
||||
<RuntimeIdentifier Condition="'$(_PlatformName)' == 'macOS'">osx-x64</RuntimeIdentifier>
|
||||
<RuntimeIdentifier Condition="'$(_PlatformName)' == 'MacCatalyst'">maccatalyst-x64</RuntimeIdentifier>
|
||||
<!--
|
||||
Workaround/hack:
|
||||
|
||||
The Microsoft.NET.RuntimeIdentifierInference.targets file is loaded
|
||||
before this file, and executes some logic depending on whether the
|
||||
RuntimeIdentifier is set or not. Since RuntimeIdentifier isn't set at
|
||||
that point (we're setting it here), we need to replicate the logic in
|
||||
the Microsoft.NET.RuntimeIdentifierInference.targets file to make sure
|
||||
things work as expected.
|
||||
|
||||
Ref: https://github.com/dotnet/runtime/issues/54406
|
||||
-->
|
||||
<SelfContained>true</SelfContained>
|
||||
<_RuntimeIdentifierUsesAppHost>false</_RuntimeIdentifierUsesAppHost>
|
||||
<UseAppHost>false</UseAppHost>
|
||||
<IntermediateOutputPath>$(IntermediateOutputPath)$(RuntimeIdentifier)\</IntermediateOutputPath>
|
||||
<OutputPath>$(OutputPath)$(RuntimeIdentifier)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
</PropertyGroup>
|
||||
<!-- This is a variation of https://github.com/dotnet/sdk/blob/873d79d861cbd001488414b9875e53acbeaed890/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L68-L96 -->
|
||||
<!-- This doesn't cover every single possibility (in particular it does not handle ARMv7s, either as a thin or fat option, and the same for ARMv7k), but that can be done by passing /p:TargetArchitectures=ARMv7s to msbuild -->
|
||||
<PropertyGroup Condition=" '$(TargetArchitectures)' == '' And '$(_PlatformName)' == 'iOS' ">
|
||||
|
|
|
@ -790,6 +790,18 @@
|
|||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<Target Name="_ValidateRuntimeIdentifier"
|
||||
Condition="'$(RuntimeIdentifier)' != '' And '$(_RuntimeIdentifierValidation)' != 'false'"
|
||||
BeforeTargets="Restore;Build;ResolvedFrameworkReference;ResolveRuntimePackAssets;ProcessFrameworkReferences">
|
||||
<PropertyGroup>
|
||||
<_IsInvalidRuntimeIdentifier Condition="'$(_PlatformName)' == 'iOS' And '$(RuntimeIdentifier)' != 'iossimulator-x64' And '$(RuntimeIdentifier)' != 'iossimulator-x86' And '$(RuntimeIdentifier)' != 'ios-arm64' And '$(RuntimeIdentifier)' != 'ios-arm' ">true</_IsInvalidRuntimeIdentifier>
|
||||
<_IsInvalidRuntimeIdentifier Condition="'$(_PlatformName)' == 'tvOS' And '$(RuntimeIdentifier)' != 'tvossimulator-x64' And '$(RuntimeIdentifier)' != 'tvos-arm64'">true</_IsInvalidRuntimeIdentifier>
|
||||
<_IsInvalidRuntimeIdentifier Condition="'$(_PlatformName)' == 'macOS' And '$(RuntimeIdentifier)' != 'osx-x64' And '$(RuntimeIdentifier)' != 'osx-arm64'">true</_IsInvalidRuntimeIdentifier>
|
||||
<_IsInvalidRuntimeIdentifier Condition="'$(_PlatformName)' == 'MacCatalyst' And '$(RuntimeIdentifier)' != 'maccatalyst-x64' And '$(RuntimeIdentifier)' != 'maccatalyst-arm64'">true</_IsInvalidRuntimeIdentifier>
|
||||
</PropertyGroup>
|
||||
<Error Condition="'$(_IsInvalidRuntimeIdentifier)' == 'true'" Text="The RuntimeIdentifier '$(RuntimeIdentifier)' is invalid." />
|
||||
</Target>
|
||||
|
||||
<!-- Install & Run -->
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-macos</TargetFramework>
|
||||
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -2,7 +2,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-ios</TargetFramework>
|
||||
<RuntimeIdentifier>iossimulator-x64</RuntimeIdentifier>
|
||||
<OutputType>Exe</OutputType>
|
||||
|
||||
<ApplicationTitle>MySingleTitle</ApplicationTitle>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-tvos</TargetFramework>
|
||||
<RuntimeIdentifier>tvossimulator-x64</RuntimeIdentifier>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace Xamarin.Tests {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[TestCase (null)]
|
||||
[TestCase ("iossimulator-x86")]
|
||||
[TestCase ("iossimulator-x64")]
|
||||
[TestCase ("ios-arm64")]
|
||||
|
@ -63,7 +64,11 @@ namespace Xamarin.Tests {
|
|||
Configuration.IgnoreIfIgnoredPlatform (platform);
|
||||
Clean (project_path);
|
||||
var properties = new Dictionary<string, string> (verbosity);
|
||||
properties ["RuntimeIdentifier"] = runtimeIdentifier;
|
||||
if (!string.IsNullOrEmpty (runtimeIdentifier)) {
|
||||
properties ["RuntimeIdentifier"] = runtimeIdentifier;
|
||||
} else {
|
||||
runtimeIdentifier = "iossimulator-x64"; // default RID for iOS projects. We set it here to make the rest of the test know where to expect files to be.
|
||||
}
|
||||
var result = DotNet.AssertBuild (project_path, properties);
|
||||
AssertThatLinkerExecuted (result);
|
||||
var appPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-ios", runtimeIdentifier, "MySingleView.app");
|
||||
|
@ -77,6 +82,7 @@ namespace Xamarin.Tests {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[TestCase (null)]
|
||||
[TestCase ("osx-x64")]
|
||||
[TestCase ("osx-arm64")]
|
||||
public void BuildMyCocoaApp (string runtimeIdentifier)
|
||||
|
@ -86,13 +92,18 @@ namespace Xamarin.Tests {
|
|||
Configuration.IgnoreIfIgnoredPlatform (platform);
|
||||
Clean (project_path);
|
||||
var properties = new Dictionary<string, string> (verbosity);
|
||||
properties ["RuntimeIdentifier"] = runtimeIdentifier;
|
||||
if (!string.IsNullOrEmpty (runtimeIdentifier)) {
|
||||
properties ["RuntimeIdentifier"] = runtimeIdentifier;
|
||||
} else {
|
||||
runtimeIdentifier = "osx-x64"; // default RID for macOS projects. We set it here to make the rest of the test know where to expect files to be.
|
||||
}
|
||||
var result = DotNet.AssertBuild (project_path, properties);
|
||||
AssertThatLinkerExecuted (result);
|
||||
AssertAppContents (platform, Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-macos", runtimeIdentifier, "MyCocoaApp.app"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase (null)]
|
||||
[TestCase ("tvossimulator-x64")]
|
||||
[TestCase ("tvos-arm64")]
|
||||
public void BuildMyTVApp (string runtimeIdentifier)
|
||||
|
@ -102,7 +113,11 @@ namespace Xamarin.Tests {
|
|||
Configuration.IgnoreIfIgnoredPlatform (platform);
|
||||
Clean (project_path);
|
||||
var properties = new Dictionary<string, string> (verbosity);
|
||||
properties ["RuntimeIdentifier"] = runtimeIdentifier;
|
||||
if (!string.IsNullOrEmpty (runtimeIdentifier)) {
|
||||
properties ["RuntimeIdentifier"] = runtimeIdentifier;
|
||||
} else {
|
||||
runtimeIdentifier = "tvossimulator-x64"; // default RID for tvOS projects. We set it here to make the rest of the test know where to expect files to be.
|
||||
}
|
||||
var result = DotNet.AssertBuild (project_path, properties);
|
||||
AssertThatLinkerExecuted (result);
|
||||
AssertAppContents (platform, Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-tvos", runtimeIdentifier, "MyTVApp.app"));
|
||||
|
@ -120,6 +135,7 @@ namespace Xamarin.Tests {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[TestCase (null)]
|
||||
[TestCase ("maccatalyst-x64")]
|
||||
[TestCase ("maccatalyst-arm64")]
|
||||
public void BuildMyCatalystApp (string runtimeIdentifier)
|
||||
|
@ -129,7 +145,11 @@ namespace Xamarin.Tests {
|
|||
Configuration.IgnoreIfIgnoredPlatform (platform);
|
||||
Clean (project_path);
|
||||
var properties = new Dictionary<string, string> (verbosity);
|
||||
properties ["RuntimeIdentifier"] = runtimeIdentifier;
|
||||
if (!string.IsNullOrEmpty (runtimeIdentifier)) {
|
||||
properties ["RuntimeIdentifier"] = runtimeIdentifier;
|
||||
} else {
|
||||
runtimeIdentifier = "maccatalyst-x64"; // default RID for Mac Catalyst projects. We set it here to make the rest of the test know where to expect files to be.
|
||||
}
|
||||
var result = DotNet.AssertBuild (project_path, properties);
|
||||
AssertThatLinkerExecuted (result);
|
||||
var appPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-maccatalyst", runtimeIdentifier, "MyCatalystApp.app");
|
||||
|
@ -428,6 +448,39 @@ namespace Xamarin.Tests {
|
|||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase (ApplePlatform.iOS, "ios-x64")] // valid RID in a previous preview (and common mistake)
|
||||
[TestCase (ApplePlatform.iOS, "iossimulator-x84")] // it's x86, not x84
|
||||
[TestCase (ApplePlatform.iOS, "iossimulator-arm64")] // we don't support this yet
|
||||
[TestCase (ApplePlatform.iOS, "helloworld")] // random text
|
||||
[TestCase (ApplePlatform.iOS, "osx-x64")] // valid RID for another platform
|
||||
[TestCase (ApplePlatform.TVOS, "tvos-x64")] // valid RID in a previous preview (and common mistake)
|
||||
[TestCase (ApplePlatform.TVOS, "tvossimulator-x46")] // it's x64, not x46
|
||||
[TestCase (ApplePlatform.TVOS, "tvossimulator-arm64")] // we don't support this yet
|
||||
[TestCase (ApplePlatform.TVOS, "helloworld")] // random text
|
||||
[TestCase (ApplePlatform.TVOS, "osx-x64")] // valid RID for another platform
|
||||
[TestCase (ApplePlatform.MacOSX, "osx-x46")] // it's x64, not x46
|
||||
[TestCase (ApplePlatform.MacOSX, "macos-arm64")] // it's osx, not macos
|
||||
[TestCase (ApplePlatform.MacOSX, "helloworld")] // random text
|
||||
[TestCase (ApplePlatform.MacOSX, "ios-arm64")] // valid RID for another platform
|
||||
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x46")] // it's x64, not x46
|
||||
[TestCase (ApplePlatform.MacCatalyst, "helloworld")] // random text
|
||||
[TestCase (ApplePlatform.MacCatalyst, "osx-x64")] // valid RID for another platform
|
||||
public void InvalidRuntimeIdentifier (ApplePlatform platform, string runtimeIdentifier)
|
||||
{
|
||||
var project = "MySimpleApp";
|
||||
Configuration.IgnoreIfIgnoredPlatform (platform);
|
||||
|
||||
var project_path = GetProjectPath (project, platform: platform);
|
||||
Clean (project_path);
|
||||
var properties = new Dictionary<string, string> (verbosity);
|
||||
properties ["RuntimeIdentifier"] = runtimeIdentifier;
|
||||
var rv = DotNet.AssertBuildFailure (project_path, properties);
|
||||
var errors = BinLog.GetBuildMessages (rv.BinLogPath).Where (v => v.Type == BuildLogEventType.Error).ToArray ();
|
||||
Assert.AreEqual (1, errors.Length, "Error count");
|
||||
Assert.AreEqual ($"The RuntimeIdentifier '{runtimeIdentifier}' is invalid.", errors [0].Message, "Error message");
|
||||
}
|
||||
|
||||
void ExecuteWithMagicWordAndAssert (string executable)
|
||||
{
|
||||
var magicWord = Guid.NewGuid ().ToString ();
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-maccatalyst</TargetFramework>
|
||||
<RuntimeIdentifier>maccatalyst-x64</RuntimeIdentifier>
|
||||
<OutputType>Exe</OutputType>
|
||||
<DefineConstants>NET</DefineConstants>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-ios</TargetFramework>
|
||||
<RuntimeIdentifier>iossimulator-x64</RuntimeIdentifier>
|
||||
<OutputType>Exe</OutputType>
|
||||
<DefineConstants>NET</DefineConstants>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-macos</TargetFramework>
|
||||
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
|
||||
<OutputType>Exe</OutputType>
|
||||
<DefineConstants>NET</DefineConstants>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-tvos</TargetFramework>
|
||||
<RuntimeIdentifier>tvossimulator-x64</RuntimeIdentifier>
|
||||
<OutputType>Exe</OutputType>
|
||||
<DefineConstants>NET;XAMCORE_3_0</DefineConstants>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
|
Загрузка…
Ссылка в новой задаче