From b6899d0a88c93aadad228fd9c6ddbcdfb31cb75b Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Wed, 9 Nov 2022 16:58:01 -0800 Subject: [PATCH 01/12] only do rid inference on publishaot etc if is publishing --- .../Microsoft.NET.RuntimeIdentifierInference.targets | 6 +++--- 1 file changed, 3 insertions(+), 3 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 a2a3f285dbaa..186a9afc2114 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 @@ -74,9 +74,9 @@ Copyright (c) .NET Foundation. All rights reserved. '$(IsRidAgnostic)' != 'true' and ( '$(SelfContained)' == 'true' or - '$(PublishReadyToRun)' == 'true' or - '$(PublishSingleFile)' == 'true' or - '$(PublishAot)' == 'true' + ('$(_IsPublishing)' == 'true' and '$(PublishReadyToRun)' == 'true') or + ('$(_IsPublishing)' == 'true' and '$(PublishSingleFile)' == 'true') or + ('$(_IsPublishing)' == 'true' and '$(PublishAot)' == 'true') )">true From c38a2f0f619d247d726621804862be600314616a Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Wed, 16 Nov 2022 15:50:38 -0800 Subject: [PATCH 02/12] Don't infer rid any time outside of publish --- .../Microsoft.NET.RuntimeIdentifierInference.targets | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 186a9afc2114..e5ba50f256cb 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 @@ -72,11 +72,12 @@ Copyright (c) .NET Foundation. All rights reserved. '$(RuntimeIdentifier)' == '' and '$(_IsExecutable)' == 'true' and '$(IsTestProject)' != 'true' and '$(IsRidAgnostic)' != 'true' and + '$(_IsPublishing)' == 'true' and ( '$(SelfContained)' == 'true' or - ('$(_IsPublishing)' == 'true' and '$(PublishReadyToRun)' == 'true') or - ('$(_IsPublishing)' == 'true' and '$(PublishSingleFile)' == 'true') or - ('$(_IsPublishing)' == 'true' and '$(PublishAot)' == 'true') + '$(PublishReadyToRun)' == 'true' or + '$(PublishSingleFile)' == 'true' or + '$(PublishAot)' == 'true' )">true From c4316668deace9a421435831edc21b30b9efced9 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 29 Nov 2022 15:23:57 -0800 Subject: [PATCH 03/12] Errors only happen if _IsPublishing --- .../Microsoft.NET.RuntimeIdentifierInference.targets | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 e5ba50f256cb..bf4518804995 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 @@ -176,19 +176,19 @@ Copyright (c) .NET Foundation. All rights reserved. Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(HasRuntimeOutput)' == 'true'"> - - - - From a711dbeb66b77b71a744cba098a7da4b2979bd62 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 29 Nov 2022 16:49:12 -0800 Subject: [PATCH 04/12] Make the AOT test call DotnetPublishCommand instead of PublishCommand --- .../GivenThatWeWantToPublishAnAotApp.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index 64c7127452ad..b56fb227b000 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -655,7 +655,7 @@ public void It_publishes_with_implicit_rid_with_NativeAotApp(string targetFramew testProject.AdditionalProperties["PublishAot"] = "true"; var testAsset = _testAssetsManager.CreateTestProject(testProject); - var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + var publishCommand = new DotnetPublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute() .Should().Pass(); From 553fc3d13586e9c714909fdd0cadfd5e0bf809e6 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 29 Nov 2022 16:55:41 -0800 Subject: [PATCH 05/12] Fix an implicit RID test to also use dotnet publish instead --- .../GivenThatWeWantToPublishAnAotApp.cs | 3 ++- .../Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs index b56fb227b000..226b33804d8f 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAnAotApp.cs @@ -658,7 +658,8 @@ public void It_publishes_with_implicit_rid_with_NativeAotApp(string targetFramew var publishCommand = new DotnetPublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute() - .Should().Pass(); + .Should() + .Pass(); } } diff --git a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs index fbe09c52e9a9..62822b4ed257 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs @@ -285,7 +285,7 @@ public void ImplicitRuntimeIdentifierOptOutCorrectlyOptsOut() var testAsset = _testAssetsManager.CreateTestProject(testProject); - var publishCommand = new PublishCommand(testAsset); + var publishCommand = new DotnetPublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute() .Should() From 76ea51fce9127c7d38ab0a56d7bbfb1e03bb1daa Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 29 Nov 2022 16:57:13 -0800 Subject: [PATCH 06/12] Fix the publish with RID require property test to expect it to pass only in the CLI dotnet --- .../Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs index 62822b4ed257..a8fc4ead6c30 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs @@ -335,7 +335,7 @@ public void PublishSuccessfullyWithRIDRequiringPropertyAndRuntimeIdentifiersNoRu testProject.AdditionalProperties["PublishReadyToRun"] = "true"; var testAsset = _testAssetsManager.CreateTestProject(testProject); - var publishCommand = new PublishCommand(testAsset); + var publishCommand = new DotnetPublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute() .Should() From 995b296226ba5ad35fe5a8a11ba0696bd294591a Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Wed, 30 Nov 2022 09:38:28 -0800 Subject: [PATCH 07/12] Make GlobalPropertyFlowTests not expect SC to give a RID on build. --- .../GlobalPropertyFlowTests.cs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Tests/Microsoft.NET.Build.Tests/GlobalPropertyFlowTests.cs b/src/Tests/Microsoft.NET.Build.Tests/GlobalPropertyFlowTests.cs index 8a960e2f52e4..612044e3e83a 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GlobalPropertyFlowTests.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GlobalPropertyFlowTests.cs @@ -86,7 +86,7 @@ public void TestGlobalPropertyFlowToLibrary(bool passSelfContained, bool passRun bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); ValidateProperties(testAsset, _referencedProject, expectSelfContained: false, expectRuntimeIdentifier: false); } @@ -103,8 +103,8 @@ public void TestGlobalPropertyFlowToExe(bool passSelfContained, bool passRuntime bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); - ValidateProperties(testAsset, _referencedProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); + ValidateProperties(testAsset, _referencedProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); } @@ -139,9 +139,9 @@ public void TestGlobalPropertyFlowToExeWithSelfContainedFalse(bool passSelfConta bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); // SelfContained will only flow to referenced project if it's explicitly passed in this case - ValidateProperties(testAsset, _referencedProject, expectSelfContained: passSelfContained, expectRuntimeIdentifier: buildingSelfContained); + ValidateProperties(testAsset, _referencedProject, expectSelfContained: passSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); } } @@ -159,11 +159,9 @@ public void TestGlobalPropertyFlowToLibraryWithRuntimeIdentifier(bool passSelfCo bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); - ValidateProperties(testAsset, _referencedProject, expectSelfContained: passSelfContained, expectRuntimeIdentifier: buildingSelfContained, - // Right now passing "--self-contained" also causes the RuntimeIdentifier to be passed as a global property. - // That should change with https://github.com/dotnet/sdk/pull/26143, which will likely require updating this and other tests in this class - expectedRuntimeIdentifier: buildingSelfContained ? "" : _referencedProject.RuntimeIdentifier); + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); + ValidateProperties(testAsset, _referencedProject, expectSelfContained: passSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier, + expectedRuntimeIdentifier: passRuntimeIdentifier ? "" : _referencedProject.RuntimeIdentifier); } [RequiresMSBuildVersionTheory("17.4.0.41702")] @@ -186,13 +184,13 @@ public void TestGlobalPropertyFlowToMultitargetedProject(bool passSelfContained, bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained, + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier, targetFramework: "net6.0"); - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained, + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier, targetFramework: "net7.0"); ValidateProperties(testAsset, _referencedProject, expectSelfContained: false, expectRuntimeIdentifier: false, targetFramework: "net6.0"); - ValidateProperties(testAsset, _referencedProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained, + ValidateProperties(testAsset, _referencedProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier, targetFramework: "net7.0"); } @@ -253,7 +251,7 @@ private static void ValidateProperties(TestAsset testAsset, TestProject testProj targetFramework = targetFramework ?? testProject.TargetFrameworks; - if (string.IsNullOrEmpty(expectedRuntimeIdentifier) && (expectSelfContained || expectRuntimeIdentifier)) + if (string.IsNullOrEmpty(expectedRuntimeIdentifier) && expectRuntimeIdentifier) { // RuntimeIdentifier might be inferred, so look at the output path to figure out what the actual value used was string dir = (Path.Combine(testAsset.TestRoot, testProject.Name, "bin", "Debug", targetFramework)); From b0251c663a5276996d6b124828fc0202e0b21a65 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Wed, 30 Nov 2022 14:08:53 -0800 Subject: [PATCH 08/12] Test RID doesnt go into build now --- ...GivenThatWeWantToBuildASelfContainedApp.cs | 26 +++++++++++++++++++ ...enThatWeWantToPublishAHelloWorldProject.cs | 4 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs index 82fbfd804c79..1a0ead735614 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs @@ -404,6 +404,32 @@ public void It_does_not_build_SelfContained_due_to_PublishSelfContained_being_tr outputDirectory.Should().NotHaveFile("hostfxr.dll"); // This file will only appear if SelfContained. } + [Theory] + [InlineData("--p:PublishReadyToRun=true")] + [InlineData("-p:PublishSingleFile=true")] + [InlineData("-p:PublishSelfContained=true")] + [InlineData("-p:SelfContained=true")] + public void It_builds_without_implicit_rid_with_RuntimeIdentifier_specific_during_publish_only_properties(string property) + { + var tfm = ToolsetInfo.CurrentTargetFramework; + var testProject = new TestProject() + { + Name = "PublishImplicitRid", + TargetFrameworks = tfm, + }; + testProject.RecordProperties("RuntimeIdentifier"); + var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: $"ItBuildsWithoutImplicitRIDOnRIDRequiringPropertiesDuringPublish_{property}"); + + var buildCommand = new DotnetBuildCommand(testAsset); + buildCommand + .Execute(property) + .Should() + .Pass(); + + var properties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: tfm); + properties["RuntimeIdentifier"].Should().Be(""); + } + [Theory] [InlineData("net7.0")] public void It_builds_a_runnable_output_with_Prefer32Bit(string targetFramework) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs index beb6d858e700..978dc4677f8a 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Xml.Linq; +using FluentAssertions; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Utils; using Microsoft.Extensions.DependencyModel; @@ -1081,7 +1082,6 @@ public void It_publishes_with_full_path_publish_profile() [InlineData("--p:PublishReadyToRun=true")] [InlineData("-p:PublishSingleFile=true")] [InlineData("-p:PublishSelfContained=true")] - [InlineData("")] public void It_publishes_with_implicit_rid_with_rid_specific_properties(string executeOptionsAndProperties) { var testProject = new TestProject() @@ -1092,7 +1092,7 @@ public void It_publishes_with_implicit_rid_with_rid_specific_properties(string e testProject.AdditionalProperties.Add("IsPublishable", "false"); var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: executeOptionsAndProperties); - var publishCommand = new PublishCommand(testAsset); + var publishCommand = new DotnetPublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); publishCommand .Execute(executeOptionsAndProperties) .Should() From 17ac4931ff375b0193419c7bbb9f6e37d0c8e1cc Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Mon, 12 Dec 2022 16:56:21 -0800 Subject: [PATCH 09/12] Infer RID for SelfContained at any time. Should check if PublishAot etc infer it by the time this happens.... --- .../targets/Microsoft.NET.RuntimeIdentifierInference.targets | 5 ++--- 1 file changed, 2 insertions(+), 3 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 bf4518804995..b2065a93c44d 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 @@ -72,9 +72,8 @@ Copyright (c) .NET Foundation. All rights reserved. '$(RuntimeIdentifier)' == '' and '$(_IsExecutable)' == 'true' and '$(IsTestProject)' != 'true' and '$(IsRidAgnostic)' != 'true' and - '$(_IsPublishing)' == 'true' and + ('$(_IsPublishing)' == 'true' or '$(SelfContained)' == 'true') and ( - '$(SelfContained)' == 'true' or '$(PublishReadyToRun)' == 'true' or '$(PublishSingleFile)' == 'true' or '$(PublishAot)' == 'true' @@ -88,7 +87,7 @@ Copyright (c) .NET Foundation. All rights reserved. $(PublishRuntimeIdentifier) - + <_UsingDefaultPlatformTarget>true From e3c84ca0fabba0c3c89b1b1d72b42278c9d4b17c Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 13 Dec 2022 11:22:05 -0800 Subject: [PATCH 10/12] Infer RID for PublishSelfContained no SelfContained as well, and fix tests regarding this. --- ...oft.NET.RuntimeIdentifierInference.targets | 11 ++++++- ...GivenThatWeWantToBuildASelfContainedApp.cs | 4 +-- .../GivenDotnetBuildBuildsCsproj.cs | 28 ++++++++++------- .../GivenDotnetOsArchOptions.cs | 31 ------------------- 4 files changed, 29 insertions(+), 45 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 b2065a93c44d..9acdab5b0041 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 @@ -67,6 +67,14 @@ Copyright (c) .NET Foundation. All rights reserved. $(PublishSelfContained) + - diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs index 1a0ead735614..8ca7b919d710 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs @@ -408,13 +408,13 @@ public void It_does_not_build_SelfContained_due_to_PublishSelfContained_being_tr [InlineData("--p:PublishReadyToRun=true")] [InlineData("-p:PublishSingleFile=true")] [InlineData("-p:PublishSelfContained=true")] - [InlineData("-p:SelfContained=true")] + [InlineData("-p:PublishAot=true")] public void It_builds_without_implicit_rid_with_RuntimeIdentifier_specific_during_publish_only_properties(string property) { var tfm = ToolsetInfo.CurrentTargetFramework; var testProject = new TestProject() { - Name = "PublishImplicitRid", + IsExe = true, TargetFrameworks = tfm, }; testProject.RecordProperties("RuntimeIdentifier"); diff --git a/src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs b/src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs index c2871b869b4b..07414392a3cc 100644 --- a/src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs +++ b/src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs @@ -254,24 +254,30 @@ public void It_does_not_warn_on_rid_with_self_contained_options_prior_to_net6() [Theory] [InlineData("--self-contained")] - [InlineData("-p:PublishTrimmed=true")] - [InlineData("")] - public void It_builds_with_implicit_rid_with_rid_specific_properties(string executeOptionsAndProperties) + public void It_builds_with_implicit_rid_with_SelfContained(string executeOptions) { - var testInstance = _testAssetsManager.CopyTestAsset("HelloWorld") - .WithSource() - .WithTargetFrameworkOrFrameworks("net6.0", false) - .Restore(Log); + var targetFramework = ToolsetInfo.CurrentTargetFramework; + var testProject = new TestProject() + { + IsExe = true, + TargetFrameworks = targetFramework + }; - new DotnetBuildCommand(Log) - .WithWorkingDirectory(testInstance.Path) - .Execute(executeOptionsAndProperties) + testProject.RecordProperties("RuntimeIdentifier"); + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + + new DotnetBuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)) + .Execute(executeOptions) .Should() .Pass() .And .NotHaveStdOutContaining("NETSDK1031") // Self Contained Checks .And - .NotHaveStdErrContaining("NETSDK1190"); // Check that publish properties don't interfere with build either + .NotHaveStdErrContaining("NETSDK1190"); // Check that publish properties don't interfere with build either + + var properties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: targetFramework); + Assert.NotEqual("", properties["RuntimeIdentifier"]); } [RequiresMSBuildVersionFact("17.4.0.41702")] diff --git a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs index 49ca2bd8fffe..872f19968158 100644 --- a/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs +++ b/src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs @@ -143,36 +143,5 @@ public void CommandsRunWithArchOption(string command) .Should() .Pass(); } - - [Fact] - public void ItUsesImplicitRidWhenNoneIsSpecifiedForSelfContained() - { - CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => - { - var msbuildPath = ""; - var currentRid = CommonOptions.GetCurrentRuntimeId(); - var command = BuildCommand.FromArgs(new string[] { "--self-contained" }, msbuildPath); - command.GetArgumentsToMSBuild() - .Should() - .StartWith($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary " + - $"-property:SelfContained=True -property:_CommandLineDefinedSelfContained=true"); - }); - } - - [Fact] - public void ItDoesNotUseImplicitRidWhenOneIsSpecifiedForSelfContained() - { - CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () => - { - var msbuildPath = ""; - var currentRid = CommonOptions.GetCurrentRuntimeId(); - var command = BuildCommand.FromArgs(new string[] { "--self-contained", "--runtime", "fake-rid" }, msbuildPath); - command.GetArgumentsToMSBuild() - .Should() - .StartWith($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary " + - $"-property:RuntimeIdentifier=fake-rid -property:_CommandLineDefinedRuntimeIdentifier=true " + - $"-property:SelfContained=True -property:_CommandLineDefinedSelfContained=true"); - }); - } } } From c3a68ecb8caf3c86a6332d07541ca24ddf1cb646 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 13 Dec 2022 13:45:41 -0800 Subject: [PATCH 11/12] Respond to PR feedback on RID Inference for Publish Only --- ...oft.NET.RuntimeIdentifierInference.targets | 16 +++++++----- ...GivenThatWeWantToBuildASelfContainedApp.cs | 13 +++++----- .../GlobalPropertyFlowTests.cs | 26 ++++++++++--------- .../TestAssetsManager.cs | 1 + 4 files changed, 31 insertions(+), 25 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 9acdab5b0041..469c238029e8 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 @@ -80,12 +80,14 @@ Copyright (c) .NET Foundation. All rights reserved. '$(RuntimeIdentifier)' == '' and '$(_IsExecutable)' == 'true' and '$(IsTestProject)' != 'true' and '$(IsRidAgnostic)' != 'true' and - ('$(_IsPublishing)' == 'true' or '$(SelfContained)' == 'true') and - ( - '$(SelfContained)' == 'true' or - '$(PublishReadyToRun)' == 'true' or - '$(PublishSingleFile)' == 'true' or - '$(PublishAot)' == 'true' + ( + '$(SelfContained)' == 'true' or + ('$(_IsPublishing)' == 'true' and + ( + '$(PublishReadyToRun)' == 'true' or + '$(PublishSingleFile)' == 'true' or + '$(PublishAot)' == 'true' + ) )">true @@ -184,7 +186,7 @@ Copyright (c) .NET Foundation. All rights reserved. Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(HasRuntimeOutput)' == 'true'"> - diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs index 8ca7b919d710..426ce36dcc6a 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs @@ -405,10 +405,10 @@ public void It_does_not_build_SelfContained_due_to_PublishSelfContained_being_tr } [Theory] - [InlineData("--p:PublishReadyToRun=true")] - [InlineData("-p:PublishSingleFile=true")] - [InlineData("-p:PublishSelfContained=true")] - [InlineData("-p:PublishAot=true")] + [InlineData("PublishReadyToRun")] + [InlineData("PublishSingleFile")] + [InlineData("PublishSelfContained")] + [InlineData("PublishAot")] public void It_builds_without_implicit_rid_with_RuntimeIdentifier_specific_during_publish_only_properties(string property) { var tfm = ToolsetInfo.CurrentTargetFramework; @@ -417,12 +417,13 @@ public void It_builds_without_implicit_rid_with_RuntimeIdentifier_specific_durin IsExe = true, TargetFrameworks = tfm, }; + testProject.AdditionalProperties[property] = "true"; testProject.RecordProperties("RuntimeIdentifier"); - var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: $"ItBuildsWithoutImplicitRIDOnRIDRequiringPropertiesDuringPublish_{property}"); + var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: property); var buildCommand = new DotnetBuildCommand(testAsset); buildCommand - .Execute(property) + .Execute() .Should() .Pass(); diff --git a/src/Tests/Microsoft.NET.Build.Tests/GlobalPropertyFlowTests.cs b/src/Tests/Microsoft.NET.Build.Tests/GlobalPropertyFlowTests.cs index 612044e3e83a..8a960e2f52e4 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GlobalPropertyFlowTests.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GlobalPropertyFlowTests.cs @@ -86,7 +86,7 @@ public void TestGlobalPropertyFlowToLibrary(bool passSelfContained, bool passRun bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); ValidateProperties(testAsset, _referencedProject, expectSelfContained: false, expectRuntimeIdentifier: false); } @@ -103,8 +103,8 @@ public void TestGlobalPropertyFlowToExe(bool passSelfContained, bool passRuntime bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); - ValidateProperties(testAsset, _referencedProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); + ValidateProperties(testAsset, _referencedProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); } @@ -139,9 +139,9 @@ public void TestGlobalPropertyFlowToExeWithSelfContainedFalse(bool passSelfConta bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); // SelfContained will only flow to referenced project if it's explicitly passed in this case - ValidateProperties(testAsset, _referencedProject, expectSelfContained: passSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); + ValidateProperties(testAsset, _referencedProject, expectSelfContained: passSelfContained, expectRuntimeIdentifier: buildingSelfContained); } } @@ -159,9 +159,11 @@ public void TestGlobalPropertyFlowToLibraryWithRuntimeIdentifier(bool passSelfCo bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier); - ValidateProperties(testAsset, _referencedProject, expectSelfContained: passSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier, - expectedRuntimeIdentifier: passRuntimeIdentifier ? "" : _referencedProject.RuntimeIdentifier); + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained); + ValidateProperties(testAsset, _referencedProject, expectSelfContained: passSelfContained, expectRuntimeIdentifier: buildingSelfContained, + // Right now passing "--self-contained" also causes the RuntimeIdentifier to be passed as a global property. + // That should change with https://github.com/dotnet/sdk/pull/26143, which will likely require updating this and other tests in this class + expectedRuntimeIdentifier: buildingSelfContained ? "" : _referencedProject.RuntimeIdentifier); } [RequiresMSBuildVersionTheory("17.4.0.41702")] @@ -184,13 +186,13 @@ public void TestGlobalPropertyFlowToMultitargetedProject(bool passSelfContained, bool buildingSelfContained = passSelfContained || passRuntimeIdentifier; - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier, + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained, targetFramework: "net6.0"); - ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier, + ValidateProperties(testAsset, _testProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained, targetFramework: "net7.0"); ValidateProperties(testAsset, _referencedProject, expectSelfContained: false, expectRuntimeIdentifier: false, targetFramework: "net6.0"); - ValidateProperties(testAsset, _referencedProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: passRuntimeIdentifier, + ValidateProperties(testAsset, _referencedProject, expectSelfContained: buildingSelfContained, expectRuntimeIdentifier: buildingSelfContained, targetFramework: "net7.0"); } @@ -251,7 +253,7 @@ private static void ValidateProperties(TestAsset testAsset, TestProject testProj targetFramework = targetFramework ?? testProject.TargetFrameworks; - if (string.IsNullOrEmpty(expectedRuntimeIdentifier) && expectRuntimeIdentifier) + if (string.IsNullOrEmpty(expectedRuntimeIdentifier) && (expectSelfContained || expectRuntimeIdentifier)) { // RuntimeIdentifier might be inferred, so look at the output path to figure out what the actual value used was string dir = (Path.Combine(testAsset.TestRoot, testProject.Name, "bin", "Debug", targetFramework)); diff --git a/src/Tests/Microsoft.NET.TestFramework/TestAssetsManager.cs b/src/Tests/Microsoft.NET.TestFramework/TestAssetsManager.cs index 81abb499c35f..e3f2de3311e2 100644 --- a/src/Tests/Microsoft.NET.TestFramework/TestAssetsManager.cs +++ b/src/Tests/Microsoft.NET.TestFramework/TestAssetsManager.cs @@ -59,6 +59,7 @@ public TestAsset CopyTestAsset( /// Defaults to the name of the caller function (presumably the test). /// Used to prevent file collisions on tests which share the same test project. /// Use this for theories. + /// Pass in the unique theory parameters that can indentify that theory from others. /// The Identifier is used to distinguish between theory child tests. Generally it should be created using a combination of all of the theory parameter values. /// This is distinct from the test project name and is used to prevent file collisions between theory tests that use the same test project. /// The extension type of the desired test project, e.g. .csproj, or .fsproj. From 6f17fc9cf1c3a1926e211c98b9a4d596b749abb2 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 13 Dec 2022 14:09:28 -0800 Subject: [PATCH 12/12] Add a missing paranth to rid inference. --- ...Microsoft.NET.RuntimeIdentifierInference.targets | 13 +++++++------ 1 file changed, 7 insertions(+), 6 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 469c238029e8..73c6643b6053 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 @@ -83,12 +83,13 @@ Copyright (c) .NET Foundation. All rights reserved. ( '$(SelfContained)' == 'true' or ('$(_IsPublishing)' == 'true' and - ( - '$(PublishReadyToRun)' == 'true' or - '$(PublishSingleFile)' == 'true' or - '$(PublishAot)' == 'true' - ) - )">true + ( + '$(PublishReadyToRun)' == 'true' or + '$(PublishSingleFile)' == 'true' or + '$(PublishAot)' == 'true' + ) + ) + )">true