Skip to content

Commit

Permalink
PublishRid now overrides UCR
Browse files Browse the repository at this point in the history
  • Loading branch information
nagilson committed Nov 2, 2022
1 parent 4130ba9 commit 266d006
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<RuntimeIdentifier Condition="'$(PlatformTarget)' == 'x86' or '$(PlatformTarget)' == ''">win7-x86</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(_IsPublishing)' == 'true' and '$(PublishRuntimeIdentifier)' != ''">
<RuntimeIdentifier>$(PublishRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(UseCurrentRuntimeIdentifier)' == ''">
<UseCurrentRuntimeIdentifier Condition="
'$(RuntimeIdentifier)' == '' and
Expand All @@ -82,6 +78,10 @@ Copyright (c) .NET Foundation. All rights reserved.
<RuntimeIdentifier>$(NETCoreSdkPortableRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(_IsPublishing)' == 'true' and '$(PublishRuntimeIdentifier)' != ''">
<RuntimeIdentifier>$(PublishRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(PlatformTarget)' == ''">
<_UsingDefaultPlatformTarget>true</_UsingDefaultPlatformTarget>
</PropertyGroup>
Expand Down
38 changes: 23 additions & 15 deletions src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,37 @@ public void PublishWithRuntimeIdentifier(bool publishNoBuild)
}

[WindowsOnlyTheory]
[InlineData("net7.0", "win-x64", "win-x86", false, false)]
[InlineData("net7.0", "win-x64", "win-x86", true, false)]
[InlineData("net7.0", "win-x64", "win-x86", true, true)]
public void PublishRuntimeIdentifierSetsRuntimeIdentifierAndDoesOrDoesntOverrideRID(string tfm, string publishRuntimeIdentifier, string runtimeIdentifier, bool runtimeIdentifierIsGlobal, bool publishRuntimeIdentifierIsGlobal)
[InlineData(false, false)]
[InlineData(true, false)]
[InlineData(true, true)]
public void PublishRuntimeIdentifierSetsRuntimeIdentifierAndDoesOrDoesntOverrideRID(bool runtimeIdentifierIsGlobal, bool publishRuntimeIdentifierIsGlobal)
{
string tfm = ToolsetInfo.CurrentTargetFramework;
string publishRuntimeIdentifier = "win-x64";
string runtimeIdentifier = "win-x86";

var testProject = new TestProject()
{
IsExe = true,
TargetFrameworks = tfm
};
testProject.AdditionalProperties["RuntimeIdentifier"] = runtimeIdentifier;
testProject.AdditionalProperties["PublishRuntimeIdentifier"] = publishRuntimeIdentifier;
if (!publishRuntimeIdentifierIsGlobal)
testProject.AdditionalProperties["PublishRuntimeIdentifier"] = publishRuntimeIdentifier;
if (!runtimeIdentifierIsGlobal)
testProject.AdditionalProperties["RuntimeIdentifier"] = runtimeIdentifier;
testProject.RecordProperties("RuntimeIdentifier");

List<string> args = new List<string>
{
$"/p:_IsPublishing=true", // Normally this would be set by the CLI (OR VS Soon TM), but this calls directly into t:/Publish.
"publish",
runtimeIdentifierIsGlobal ? $"/p:RuntimeIdentifier={runtimeIdentifier}" : "",
publishRuntimeIdentifierIsGlobal ? $"/p:PublishRuntimeIdentifier={publishRuntimeIdentifier}" : ""
};

var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: $"{publishRuntimeIdentifierIsGlobal}-{runtimeIdentifierIsGlobal}");
var publishCommand = new PublishCommand(testAsset);
var publishCommand = new DotnetPublishCommand(Log);
publishCommand
.WithWorkingDirectory(testAsset.Path)
.Execute(args.ToArray())
.Should()
.Pass();
Expand All @@ -230,10 +237,11 @@ public void PublishRuntimeIdentifierSetsRuntimeIdentifierAndDoesOrDoesntOverride
Assert.True(finalRid == expectedRid); // This assert is theoretically worthless as the above code will fail if the RID path is wrong.
}

[WindowsOnlyTheory]
[InlineData("net7.0", "tizen")] // tizen is an arbitrary nonwindows rid, picked because it will be different from a windows rid.
public void PublishRuntimeIdentifierDoesNotOverrideUseCurrentRuntime(string tfm, string publishRid)
[WindowsOnlyFact]
public void PublishRuntimeIdentifierOverridesUseCurrentRuntime()
{
string tfm = ToolsetInfo.CurrentTargetFramework;
string publishRid = "linux-x64"; // linux is arbitrarily picked; just because it is different than a windows RID.
var testProject = new TestProject()
{
IsExe = true,
Expand All @@ -245,7 +253,7 @@ public void PublishRuntimeIdentifierDoesNotOverrideUseCurrentRuntime(string tfm,
testProject.RecordProperties("RuntimeIdentifier");
testProject.RecordProperties("NETCoreSdkPortableRuntimeIdentifier");

var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: "UCR_PUBLISH_RID_OVERRIDES");
var testAsset = _testAssetsManager.CreateTestProject(testProject);
var publishCommand = new PublishCommand(testAsset);
publishCommand
.Execute($"/p:_IsPublishing=true")
Expand All @@ -258,10 +266,10 @@ public void PublishRuntimeIdentifierDoesNotOverrideUseCurrentRuntime(string tfm,

var properties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: tfm, runtimeIdentifier: testResolvedRid);
var finalRid = properties["RuntimeIdentifier"];
var expectedRid = properties["NETCoreSdkPortableRuntimeIdentifier"];
var ucrRid = properties["NETCoreSdkPortableRuntimeIdentifier"];

Assert.True(expectedRid == testResolvedRid);
Assert.True(finalRid == expectedRid); // This assert is theoretically worthless as the above code will fail if the RID path is wrong.
Assert.True(publishRid == testResolvedRid);
Assert.True(finalRid == publishRid); // This assert is theoretically worthless as the above code will fail if the RID path is wrong.
}

[Fact]
Expand Down

0 comments on commit 266d006

Please sign in to comment.