diff --git a/src/Cli/dotnet/commands/dotnet-publish/Program.cs b/src/Cli/dotnet/commands/dotnet-publish/Program.cs index b75fa918da25..cd81e6bea7f5 100644 --- a/src/Cli/dotnet/commands/dotnet-publish/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-publish/Program.cs @@ -46,7 +46,7 @@ public static PublishCommand FromParseResult(ParseResult parseResult, string msb var msbuildArgs = new List() { "-target:Publish", - "--property:_IsPublishing=true" + "--property:_IsPublishing=true" // This property will not hold true for MSBuild /t:Publish. VS should also inject this property in the future. }; IEnumerable slnOrProjectArgs = parseResult.GetValueForArgument(PublishCommandParser.SlnOrProjectArgument); 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 279717af4f5c..b9a62488bb42 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,6 +61,10 @@ Copyright (c) .NET Foundation. All rights reserved. win7-x86 + + $(PublishRuntimeIdentifier) + + 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. + runtimeIdentifierIsGlobal ? $"/p:RuntimeIdentifier={runtimeIdentifier}" : "", + publishRuntimeIdentifierIsGlobal ? $"/p:PublishRuntimeIdentifier={publishRuntimeIdentifier}" : "" + }; + + var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: $"{publishRuntimeIdentifierIsGlobal}-{runtimeIdentifierIsGlobal}"); + var publishCommand = new PublishCommand(testAsset); + publishCommand + .Execute(args.ToArray()) + .Should() + .Pass(); + + string expectedRid = runtimeIdentifierIsGlobal ? runtimeIdentifier : publishRuntimeIdentifier; + var properties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: tfm, runtimeIdentifier: expectedRid); + var finalRid = properties["RuntimeIdentifier"]; + + Assert.True(finalRid == expectedRid); // This assert is theoretically worthless as the above code will fail if the RID path is wrong. + } + + [WindowsOnlyFact] + [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) + { + var testProject = new TestProject() + { + IsExe = true, + TargetFrameworks = tfm + }; + + testProject.AdditionalProperties["UseCurrentRuntimeIdentifier"] = "true"; + testProject.AdditionalProperties["PublishRuntimeIdentifier"] = publishRid; + testProject.RecordProperties("RuntimeIdentifier"); + + var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: "UCR_PUBLISH_RID_OVERRIDES"); + var publishCommand = new PublishCommand(testAsset); + publishCommand + .Execute($"/p:_IsPublishing=true") + .Should() + .Pass(); + + var currentRid = EnvironmentInfo.GetCompatibleRid(testProject.TargetFrameworks); + var properties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: tfm, runtimeIdentifier: currentRid); + var finalRid = properties["RuntimeIdentifier"]; + + Assert.True(finalRid == currentRid); // This assert is theoretically worthless as the above code will fail if the RID path is wrong. + } + [Fact] public void ImplicitRuntimeIdentifierOptOutCorrecltyOptsOut() {