From 266d0065dc00cc8432f4031f7830ba0f0435a7e0 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 1 Nov 2022 14:30:41 -0700 Subject: [PATCH] PublishRid now overrides UCR --- ...oft.NET.RuntimeIdentifierInference.targets | 8 ++-- .../RuntimeIdentifiersTests.cs | 38 +++++++++++-------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets index b9a62488bb42..f476473829d0 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets @@ -61,10 +61,6 @@ Copyright (c) .NET Foundation. All rights reserved. win7-x86 - - $(PublishRuntimeIdentifier) - - + $(PublishRuntimeIdentifier) + + <_UsingDefaultPlatformTarget>true diff --git a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs index 069eae09b902..8ca26dfe5926 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs @@ -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 args = new List { - $"/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(); @@ -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, @@ -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") @@ -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]