From 742829507418c36f2a7287427857fd5b8fb78d54 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 11 Oct 2022 14:53:20 -0700 Subject: [PATCH 1/3] Add test that correctly fails atm --- .../RuntimeIdentifiersTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs index facaa4ac7ce5..2cd116d33b61 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Xml.Linq; using FluentAssertions; using Microsoft.DotNet.Cli.Utils; using Microsoft.NET.TestFramework; @@ -218,5 +219,36 @@ public void DuplicateRuntimeIdentifiers() .Pass(); } + + [Fact] + public void It_Publishes_Successfully_With_RID_Requiring_Properties_And_RuntimeIdentifierS_but_no_RuntimeIdentifier() + { + var targetFramework = ToolsetInfo.CurrentTargetFramework; + var runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework); + var testAsset = _testAssetsManager + .CopyTestAsset("HelloWorld") + .WithSource() + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "RuntimeIdentifiers", runtimeIdentifier)); + propertyGroup.Add(new XElement(ns + "PublishReadyToRun", "true")); + }); + + var buildCommand = new BuildCommand(testAsset); + buildCommand + .Execute() + .Should() + .Pass(); + + var outputDirectory = buildCommand.GetOutputDirectory(targetFramework, runtimeIdentifier: runtimeIdentifier); + + var publishCommand = new PublishCommand(testAsset); + publishCommand + .Execute() + .Should() + .Pass(); + } } } From 519fbdb79f0629a8ce60e30cdc4a4ebdda4254c7 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 11 Oct 2022 15:02:01 -0700 Subject: [PATCH 2/3] Imply RID For RuntimeIdentifiers --- .../Microsoft.NET.RuntimeIdentifierInference.targets | 9 ++++----- 1 file changed, 4 insertions(+), 5 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 84b21ee0dd82..81f89c806192 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 @@ -64,7 +64,6 @@ Copyright (c) .NET Foundation. All rights reserved. - - - - From 6018960e7b496760bf56c53efcac03780d6d4a57 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Mon, 17 Oct 2022 11:44:03 -0700 Subject: [PATCH 3/3] Clean up test code --- .../RuntimeIdentifiersTests.cs | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs index 2cd116d33b61..1c5e8dc057ac 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs @@ -221,28 +221,19 @@ public void DuplicateRuntimeIdentifiers() } [Fact] - public void It_Publishes_Successfully_With_RID_Requiring_Properties_And_RuntimeIdentifierS_but_no_RuntimeIdentifier() + public void PublishSuccessfullyWithRIDRequiringPropertyAndRuntimeIdentifiersNoRuntimeIdentifier() { var targetFramework = ToolsetInfo.CurrentTargetFramework; var runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework); - var testAsset = _testAssetsManager - .CopyTestAsset("HelloWorld") - .WithSource() - .WithProjectChanges(project => - { - var ns = project.Root.Name.Namespace; - var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); - propertyGroup.Add(new XElement(ns + "RuntimeIdentifiers", runtimeIdentifier)); - propertyGroup.Add(new XElement(ns + "PublishReadyToRun", "true")); - }); - - var buildCommand = new BuildCommand(testAsset); - buildCommand - .Execute() - .Should() - .Pass(); + var testProject = new TestProject() + { + IsExe = true, + TargetFrameworks = targetFramework + }; - var outputDirectory = buildCommand.GetOutputDirectory(targetFramework, runtimeIdentifier: runtimeIdentifier); + testProject.AdditionalProperties["RuntimeIdentifiers"] = runtimeIdentifier; + testProject.AdditionalProperties["PublishReadyToRun"] = "true"; + var testAsset = _testAssetsManager.CreateTestProject(testProject); var publishCommand = new PublishCommand(testAsset); publishCommand