From 0d164ae9f05df64b13afc6a21e332b12d85896a0 Mon Sep 17 00:00:00 2001 From: weihanli Date: Sat, 14 Aug 2021 10:20:09 +0800 Subject: [PATCH] UseCurrentRuntimeIdentifier when no rid specified --- src/Cli/dotnet/commands/dotnet-publish/Program.cs | 7 ++++++- .../GivenThatWeWantToPublishASelfContainedApp.cs | 6 ++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-publish/Program.cs b/src/Cli/dotnet/commands/dotnet-publish/Program.cs index 40fbb1637421..d2ab1db5736f 100644 --- a/src/Cli/dotnet/commands/dotnet-publish/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-publish/Program.cs @@ -39,7 +39,12 @@ public static PublishCommand FromArgs(string[] args, string msbuildPath = null) parseResult.HasOption(PublishCommandParser.NoSelfContainedOption)); msbuildArgs.AddRange(parseResult.OptionValuesToBeForwarded(PublishCommandParser.GetCommand())); - + + if (parseResult.GetCommandLineRuntimeIdentifier() is null) + { + msbuildArgs.AddRange(new[] { "-property:UseCurrentRuntimeIdentifier=True" }); + } + msbuildArgs.AddRange(parseResult.ValueForArgument>(PublishCommandParser.SlnOrProjectArgument) ?? Array.Empty()); bool noRestore = parseResult.HasOption(PublishCommandParser.NoRestoreOption) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASelfContainedApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASelfContainedApp.cs index 8a7dc735d420..66fb660badc4 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASelfContainedApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASelfContainedApp.cs @@ -25,7 +25,7 @@ public GivenThatWeWantToPublishASelfContainedApp(ITestOutputHelper log) : base(l } [Fact] - public void It_errors_when_publishing_self_contained_app_without_rid() + public void It_should_not_fail_when_publishing_self_contained_app_without_rid() { var testAsset = _testAssetsManager .CopyTestAsset(TestProjectName) @@ -37,9 +37,7 @@ public void It_errors_when_publishing_self_contained_app_without_rid() "/p:SelfContained=true", $"/p:TargetFramework={TargetFramework}") .Should() - .Fail() - .And - .HaveStdOutContaining(Strings.CannotHaveSelfContainedWithoutRuntimeIdentifier); + .Pass(); } [Fact]