From bcaed2565b26aeeda25bbb8f8335164aed1db1d9 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Mon, 17 Oct 2022 16:40:24 -0700 Subject: [PATCH 01/10] Don't infer rid on non exe project type --- .../targets/Microsoft.NET.RuntimeIdentifierInference.targets | 1 + 1 file changed, 1 insertion(+) 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..68d7b11ca93b 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 @@ -65,6 +65,7 @@ Copyright (c) .NET Foundation. All rights reserved. ( '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' and + '$(OutputType)' == 'Exe' and ( '$(SelfContained)' == 'true' or '$(PublishReadyToRun)' == 'true' or From a80d6b5fa1bca09e9938f1d10120d0c9df94cca4 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 18 Oct 2022 10:10:55 -0700 Subject: [PATCH 02/10] Add opt out feature and tests --- .../Program.cs | 8 +++++ .../lib/Class1.cs | 5 +++ .../lib/lib.csproj | 10 ++++++ .../newc.csproj | 17 +++++++++ ...oft.NET.RuntimeIdentifierInference.targets | 3 +- ...enThatWeWantToPublishASingleFileLibrary.cs | 35 +++++++++++++++++++ .../RuntimeIdentifiersTests.cs | 24 +++++++++++++ 7 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/Program.cs create mode 100644 src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/lib/Class1.cs create mode 100644 src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/lib/lib.csproj create mode 100644 src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/newc.csproj create mode 100644 src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs diff --git a/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/Program.cs b/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/Program.cs new file mode 100644 index 000000000000..27b8e2e2d5bb --- /dev/null +++ b/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/Program.cs @@ -0,0 +1,8 @@ +namespace newc; + +static class Program +{ + static void Main() + { + } +} \ No newline at end of file diff --git a/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/lib/Class1.cs b/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/lib/Class1.cs new file mode 100644 index 000000000000..15831cf6e227 --- /dev/null +++ b/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/lib/Class1.cs @@ -0,0 +1,5 @@ +namespace lib; +public class Class1 +{ + +} diff --git a/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/lib/lib.csproj b/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/lib/lib.csproj new file mode 100644 index 000000000000..edb25d44def3 --- /dev/null +++ b/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/lib/lib.csproj @@ -0,0 +1,10 @@ + + + + net7.0 + enable + enable + true + + + diff --git a/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/newc.csproj b/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/newc.csproj new file mode 100644 index 000000000000..01cda608aa97 --- /dev/null +++ b/src/Assets/TestProjects/AppWithLibrarySDKStyleThatPublishesSingleFile/newc.csproj @@ -0,0 +1,17 @@ + + + + WinExe + net7.0-windows + enable + true + enable + true + win-x86 + + + + + + + \ No newline at end of file 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 68d7b11ca93b..81aba921f523 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 @@ -65,7 +65,8 @@ Copyright (c) .NET Foundation. All rights reserved. ( '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' and - '$(OutputType)' == 'Exe' and + '$(_IsExecutable)' == 'true' and + '$(DisableImplicitRuntimeIdentifier)' == '' and ( '$(SelfContained)' == 'true' or '$(PublishReadyToRun)' == 'true' or diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs new file mode 100644 index 000000000000..3e7ddef04e0a --- /dev/null +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Commands; +using Xunit; +using Xunit.Abstractions; + +namespace Microsoft.NET.Publish.Tests +{ + public class GivenThatWeWantToPublishASingleFileLibrary : SdkTest + { + public GivenThatWeWantToPublishASingleFileLibrary(ITestOutputHelper log) : base(log) + { + } + + [Fact] + // Tests regression on https://github.com/dotnet/sdk/pull/28484 + public void ItPublishesSuccessfullyWithRIDAndPublishSingleFileLibrary() + { + var testAsset = _testAssetsManager + .CopyTestAsset("AppWithLibrarySDKStyleThatPublishesSingleFile") + .WithSource(); + + var publishCommand = new PublishCommand(testAsset); + publishCommand.Execute() + .Should() + .Pass(); + } + + } + +} diff --git a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs index facaa4ac7ce5..22e8d9d97419 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs @@ -193,6 +193,30 @@ public void PublishWithRuntimeIdentifier(bool publishNoBuild) } } + [Fact] + public void ImplicitRuntimeIdentifierOptOutCorrecltyOptsOut() + { + var targetFramework = ToolsetInfo.CurrentTargetFramework; + var runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework); + var testProject = new TestProject() + { + IsExe = true, + TargetFrameworks = targetFramework + }; + testProject.AdditionalProperties["SelfContained"] = "true"; + testProject.AdditionalProperties["DisableImplicitRuntimeIdentifier"] = "true"; + + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + var publishCommand = new PublishCommand(testAsset); + publishCommand + .Execute() + .Should() + .Fail() + .And + .HaveStdOutContaining("NETSDK1191"); + } + [Fact] public void DuplicateRuntimeIdentifiers() { From 10c3bc565581145197aa72dd45c4d6689e126546 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 18 Oct 2022 11:54:09 -0700 Subject: [PATCH 03/10] Update src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets Co-authored-by: Rainer Sigwald --- .../targets/Microsoft.NET.RuntimeIdentifierInference.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 81aba921f523..7907827b54aa 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 @@ -66,7 +66,7 @@ Copyright (c) .NET Foundation. All rights reserved. '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' and '$(_IsExecutable)' == 'true' and - '$(DisableImplicitRuntimeIdentifier)' == '' and + '$(DisableImplicitRuntimeIdentifier)' != 'true' and ( '$(SelfContained)' == 'true' or '$(PublishReadyToRun)' == 'true' or From 47c024b79d6e66607b159fed301388302adbe17a Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 18 Oct 2022 12:22:05 -0700 Subject: [PATCH 04/10] Make it a win only fact --- .../GivenThatWeWantToPublishASingleFileLibrary.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs index 3e7ddef04e0a..13de2a8f2c61 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs @@ -16,12 +16,14 @@ public GivenThatWeWantToPublishASingleFileLibrary(ITestOutputHelper log) : base( { } - [Fact] + [WindowsOnlyFact] // Tests regression on https://github.com/dotnet/sdk/pull/28484 public void ItPublishesSuccessfullyWithRIDAndPublishSingleFileLibrary() { + var targetFramework = ToolsetInfo.CurrentTargetFramework; var testAsset = _testAssetsManager .CopyTestAsset("AppWithLibrarySDKStyleThatPublishesSingleFile") + .WithTargetFramework(targetFramework) .WithSource(); var publishCommand = new PublishCommand(testAsset); From fb14de36a8498340d23458da9ec83fabdde25002 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 18 Oct 2022 12:44:55 -0700 Subject: [PATCH 05/10] make the test fail in the old scenario --- .../GivenThatWeWantToPublishASingleFileLibrary.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs index 13de2a8f2c61..445e03cd5823 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileLibrary.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.IO; using FluentAssertions; using Microsoft.NET.TestFramework; using Microsoft.NET.TestFramework.Assertions; @@ -30,6 +31,12 @@ public void ItPublishesSuccessfullyWithRIDAndPublishSingleFileLibrary() publishCommand.Execute() .Should() .Pass(); + + // It would be better if we could somehow check the library binlog or something for a RID instead. + var exeFolder = publishCommand.GetOutputDirectory(targetFramework: targetFramework); + // Parent: RID, then TFM, then Debug, then bin, then the test folder + var ridlessLibraryDllPath = Path.Combine(exeFolder.Parent.Parent.Parent.Parent.FullName, "lib", "bin", "Debug", targetFramework, "lib.dll"); + Assert.True(File.Exists(ridlessLibraryDllPath)); } } From d3ed325879986b270a122884e8fc31f35a633503 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 18 Oct 2022 13:31:36 -0700 Subject: [PATCH 06/10] Consider that TestProjects May be Exe Projects without Being Tagged as Exe Co-authored-by: Daniel Plaisted --- .../targets/Microsoft.NET.RuntimeIdentifierInference.targets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 7907827b54aa..39ed10b7e9ec 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 @@ -65,7 +65,8 @@ Copyright (c) .NET Foundation. All rights reserved. ( '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' and - '$(_IsExecutable)' == 'true' and + '$(_IsExecutable)' == 'true' and '$(IsTestProject)' != 'true' and + '$(IsRidAgnostic)' != 'true' and '$(DisableImplicitRuntimeIdentifier)' != 'true' and ( '$(SelfContained)' == 'true' or From b25681425dff71b7510c0183b453cc34e1492802 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Wed, 19 Oct 2022 12:03:16 -0700 Subject: [PATCH 07/10] Remove opt out feature and put it into UCR --- ...oft.NET.RuntimeIdentifierInference.targets | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 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 39ed10b7e9ec..084a58848b66 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,20 +61,22 @@ Copyright (c) .NET Foundation. All rights reserved. win7-x86 - + + '$(IsRidAgnostic)' != 'true') and + ( + '$(SelfContained)' == 'true' or + '$(PublishReadyToRun)' == 'true' or + '$(PublishSingleFile)' == 'true' or + '$(PublishAot)' == 'true' + )"> + true + + + $(NETCoreSdkPortableRuntimeIdentifier) From d1c874482431e3c45e7860236719d57a81f01146 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Wed, 19 Oct 2022 13:58:48 -0700 Subject: [PATCH 08/10] Fix tests. Only thing remaining is to improve test quality --- .../targets/Microsoft.NET.RuntimeIdentifierInference.targets | 2 +- .../Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 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 084a58848b66..33d6f09698e2 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 @@ -66,7 +66,7 @@ Copyright (c) .NET Foundation. All rights reserved. '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' and '$(_IsExecutable)' == 'true' and '$(IsTestProject)' != 'true' and - '$(IsRidAgnostic)' != 'true') and + '$(IsRidAgnostic)' != 'true' and ( '$(SelfContained)' == 'true' or '$(PublishReadyToRun)' == 'true' or diff --git a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs index 22e8d9d97419..aa9022509be9 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs @@ -204,7 +204,7 @@ public void ImplicitRuntimeIdentifierOptOutCorrecltyOptsOut() TargetFrameworks = targetFramework }; testProject.AdditionalProperties["SelfContained"] = "true"; - testProject.AdditionalProperties["DisableImplicitRuntimeIdentifier"] = "true"; + testProject.AdditionalProperties["UseCurrentRuntime"] = "false"; var testAsset = _testAssetsManager.CreateTestProject(testProject); From a00b2cf796ca568a5bba2fa616aab25e0ac992e3 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Wed, 19 Oct 2022 15:20:50 -0700 Subject: [PATCH 09/10] Fix whitespace --- .../targets/Microsoft.NET.RuntimeIdentifierInference.targets | 3 +-- 1 file changed, 1 insertion(+), 2 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 33d6f09698e2..e6e692882f6d 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,8 +72,7 @@ Copyright (c) .NET Foundation. All rights reserved. '$(PublishReadyToRun)' == 'true' or '$(PublishSingleFile)' == 'true' or '$(PublishAot)' == 'true' - )"> - true + )">true From d3173a293c1701bc156af691eb37799e12de139d Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Wed, 19 Oct 2022 16:17:16 -0700 Subject: [PATCH 10/10] Fix tests --- .../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 aa9022509be9..066c2733742e 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs @@ -204,7 +204,7 @@ public void ImplicitRuntimeIdentifierOptOutCorrecltyOptsOut() TargetFrameworks = targetFramework }; testProject.AdditionalProperties["SelfContained"] = "true"; - testProject.AdditionalProperties["UseCurrentRuntime"] = "false"; + testProject.AdditionalProperties["UseCurrentRuntimeIdentifier"] = "false"; var testAsset = _testAssetsManager.CreateTestProject(testProject);