diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx index e7bbce4e6483..58c975d2245e 100644 --- a/src/Tasks/Common/Resources/Strings.resx +++ b/src/Tasks/Common/Resources/Strings.resx @@ -879,4 +879,8 @@ You may need to build the project on another operating system or architecture, o NETSDK1193: If PublishSelfContained is set, it must be either true or false. The value given was '{0}'. {StrBegin="NETSDK1193: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index f26cb34338c0..273e455fd159 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: Zadejte parametr RuntimeIdentifier. {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: Soubor seznamu modulu runtime {0} nebyl nalezen. Tady můžete tuto chybu nahlásit týmu .NET: https://aka.ms/dotnet-sdk-issue. diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index 4016a605174f..036570dd2798 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: Geben Sie einen RuntimeIdentifier an. {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: Die Runtimelistendatei "{0}" wurde nicht gefunden. Melden Sie diesen Fehler hier dem .NET-Team: https://aka.ms/dotnet-sdk-issue. diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index 7e6051c38529..e2850f39e106 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: Especificar un valor para RuntimeIdentifier {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: No se encontró el archivo de lista del entorno de ejecución "{0}". Notifique este error al equipo de .NET aquí: https://aka.ms/dotnet-sdk-issue. diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index 2bccac9cb792..24049cfc778e 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: Spécifiez un RuntimeIdentifier {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: Le fichier de liste de runtime '{0}' est introuvable. Signalez cette erreur à l'équipe .NET ici : https://aka.ms/dotnet-sdk-issue. diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index a34612dfb7aa..66eff0ec2506 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: specificare un elemento RuntimeIdentifier {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: il file di elenco di runtime '{0}' non è stato trovato. Segnalare questo errore al team di .NET all'indirizzo: https://aka.ms/dotnet-sdk-issue. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index 22eedf082e4d..83f97fc3e2c9 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: RuntimeIdentifier の指定 {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: ランタイム リスト ファイル '{0}' が見つかりませんでした。https://aka.ms/dotnet-sdk-issue で、このエラーを .NET チームに報告してください。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index 13f2a49fe0f1..4dc70cba756d 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: RuntimeIdentifier 지정 {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: 런타임 목록 파일 '{0}'을(를) 찾을 수 없습니다. https://aka.ms/dotnet-sdk-issue에서 .NET 팀에 이 오류를 보고하세요. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index 17a6c5fccb80..8cbdaa8c6879 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: Określ element RuntimeIdentifier {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: Nie odnaleziono pliku listy środowiska uruchomieniowego „{0}”. Zgłoś ten błąd zespołowi platformy .NET tutaj: https://aka.ms/dotnet-sdk-issue. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index d9a01d84e127..9a77d67b2b2e 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: Especifique um RuntimeIdentifier {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: o arquivo da lista de runtime '{0}' não foi encontrado. Relate esse erro à equipe do .NET aqui: https://aka.ms/dotnet-sdk-issue. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index 99e7fbc8fbd7..8111c2b66d44 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: укажите RuntimeIdentifier {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: не найден файл списка среды выполнения "{0}". Сообщите об этой ошибке группе разработчиков .NET по следующему адресу: https://aka.ms/dotnet-sdk-issue. diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index 0f163128f2c1..1701f348c4ca 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: Bir RuntimeIdentifier belirtin {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: '{0}' çalışma zamanı listesi dosyası bulunamadı. Bu hatayı https://aka.ms/dotnet-sdk-issue adresinden .NET ekibine bildirin. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index 03bf88f880dc..57e6a5600643 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: 指定一个 RuntimeIdentifier {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: 找不到运行时列表文件“{0}”。请在此处将此错误报告给 .NET 团队: https://aka.ms/dotnet-sdk-issue。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index 708354dc73f5..86993f4c7b27 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -775,6 +775,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1028: 指定 RuntimeIdentifier {StrBegin="NETSDK1028: "} + + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + NETSDK1194: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically implies SelfContained. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly. + {StrBegin="NETSDK1194: "} + NETSDK1109: Runtime list file '{0}' was not found. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue. NETSDK1109: 找不到執行階段清單檔案 '{0}'。請將此錯誤回報給 .NET 小組: https://aka.ms/dotnet-sdk-issue。 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..af2007ef5415 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,14 @@ Copyright (c) .NET Foundation. All rights reserved. win7-x86 + + true + + + + $(NETCoreSdkRuntimeIdentifier) + + @@ -137,7 +145,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_SelfContainedWasSpecified Condition="'$(SelfContained)' != ''">true - true + true false <_RuntimeIdentifierUsesAppHost Condition="$(RuntimeIdentifier.StartsWith('ios')) or $(RuntimeIdentifier.StartsWith('tvos')) or $(RuntimeIdentifier.StartsWith('maccatalyst')) or $(RuntimeIdentifier.StartsWith('android')) or $(RuntimeIdentifier.StartsWith('browser'))">false <_RuntimeIdentifierUsesAppHost Condition="'$(_RuntimeIdentifierUsesAppHost)' == ''">true @@ -215,6 +223,11 @@ Copyright (c) .NET Foundation. All rights reserved. + + + diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs index 82fbfd804c79..f42ae2d10ccb 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs @@ -377,6 +377,42 @@ public void It_can_publish_runtime_specific_apps_with_library_dependencies_self_ publishCommand.Execute(new[] { "-property:SelfContained=true", "-property:_CommandLineDefinedSelfContained=true", $"-property:RuntimeIdentifier={rid}", "-property:_CommandLineDefinedRuntimeIdentifier=true" }).Should().Pass().And.NotHaveStdOutContaining("warning"); } + [Theory] + [InlineData("net7.0")] + [InlineData("net8.0")] + public void It_does_or_doesnt_imply_SelfContained_based_on_RuntimeIdentifier_and_TargetFramework(string targetFramework) + { + 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 + "RuntimeIdentifier", runtimeIdentifier)); + }); + + var buildCommand = new BuildCommand(testAsset); + buildCommand + .Execute() + .Should() + .Pass(); + + var outputDirectory = buildCommand.GetOutputDirectory(targetFramework, runtimeIdentifier: runtimeIdentifier); + var selfContainedExecutable = $"HelloWorld{Constants.ExeSuffix}"; + string selfContainedExecutableFullPath = Path.Combine(outputDirectory.FullName, selfContainedExecutable); + + if (targetFramework == "net7.0") + { + Assert.True(File.Exists(selfContainedExecutableFullPath)); + } + else + { + Assert.False(File.Exists(selfContainedExecutableFullPath)); // RuntimeIdentifier no longer implies SelfContained for TFM >= 8 + } + } + [Fact] public void It_does_not_build_SelfContained_due_to_PublishSelfContained_being_true() { @@ -404,6 +440,45 @@ 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("net7.0", true)] + [InlineData("net7.0", false)] + [InlineData("net8.0", false)] + public void It_does_or_doesnt_warn_based_on_SelfContained_and_TargetFramework_breaking_RID_change(string targetFramework, bool defineSelfContained) + { + 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 + "RuntimeIdentifier", runtimeIdentifier)); + propertyGroup.Add(new XElement(ns + "SelfContained", defineSelfContained ? "true" : "")); + }); + + var buildCommand = new BuildCommand(testAsset); + var commandResult = buildCommand.Execute(); + + if (targetFramework == "net7.0" && !defineSelfContained) + { + commandResult + .Should() + .Pass() + .And + .HaveStdOutContaining(Strings.RuntimeIdentifierWillNoLongerImplySelfContained); + } + else + { + commandResult + .Should() + .Pass() + .And + .NotHaveStdOutContaining(Strings.RuntimeIdentifierWillNoLongerImplySelfContained); + } + } + [Theory] [InlineData("net7.0")] public void It_builds_a_runnable_output_with_Prefer32Bit(string targetFramework) diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseVB.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseVB.cs index e6e65e456284..0f24447d65f3 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseVB.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseVB.cs @@ -143,8 +143,8 @@ private static (VBRuntime, string[]) GetExpectedOutputs(string targetFramework, }); case ("netcoreapp3.0", false): - return (VBRuntime.Referenced, new[] - { + return (VBRuntime.Referenced, new[] + { "HelloWorld.dll", "HelloWorld.pdb", "HelloWorld.deps.json", diff --git a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs index fbe09c52e9a9..d7ca39f20ebc 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Formats.Asn1; using System.IO; using System.Linq; using System.Reflection; @@ -23,8 +24,18 @@ namespace Microsoft.NET.Publish.Tests { public class RuntimeIdentifiersTests : SdkTest { + + TestProject _testProject; + public RuntimeIdentifiersTests(ITestOutputHelper log) : base(log) { + _testProject = new TestProject("TestProject") + { + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, + IsExe = true + }; + + _testProject.RecordProperties("RuntimeIdentifier", "SelfContained", "RuntimeIdentifiers"); } // Run on core MSBuild only as using a local packages folder hits long path issues on full MSBuild @@ -320,6 +331,67 @@ public void DuplicateRuntimeIdentifiers() } + [Theory] + [InlineData("net7.0", "true")] + [InlineData("net7.0", "")] + [InlineData("net8.0", "")] + [InlineData("net8.0", "true")] + [InlineData("net8.0", "false")] + public void RuntimeSpecificEnablesOrDisablesRuntimeIdentifierByDefaultBasedOnValueAndTargetFramework(string targetFramework, string runtimeSpecific) + { + TestAsset testAsset = _testAssetsManager.CreateTestProject(_testProject, identifier: $"{targetFramework}_{runtimeSpecific}") + .WithTargetFramework(targetFramework) + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "RuntimeSpecific", runtimeSpecific)); + }); + + var expectedRuntimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework); + new DotnetBuildCommand(testAsset) + .Execute($"/p:NETCoreSdkRuntimeIdentifier={expectedRuntimeIdentifier}") + .Should() + .Pass(); + + if ((runtimeSpecific != "false" && targetFramework == "net8.0") || runtimeSpecific == "true" && targetFramework == "net7.0") + { + var properties = _testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: targetFramework); + var resolvedRid = properties["RuntimeIdentifier"]; + Assert.True(resolvedRid == expectedRuntimeIdentifier); + } + else + { + var properties = _testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: targetFramework); + var resolvedRid = properties["RuntimeIdentifier"]; + Assert.True(resolvedRid == ""); + } + } + + [Theory] + [InlineData("net8.0")] + public void RuntimeIdentifiersDisablesRuntimeSpecificFDDBehavior(string targetFramework) + { + var expectedRuntimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework); + TestAsset testAsset = _testAssetsManager.CreateTestProject(_testProject, identifier: $"RuntimeIdentifierS_{targetFramework}") // the S is intentional to call atention to it + .WithTargetFramework(targetFramework) + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "RuntimeIdentifiers", $"{expectedRuntimeIdentifier};{expectedRuntimeIdentifier}")); + }); + + new DotnetBuildCommand(testAsset) + .Execute($"/p:NETCoreSdkRuntimeIdentifier={expectedRuntimeIdentifier}") + .Should() + .Pass(); + + var properties = _testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: targetFramework); + var resolvedRid = properties["RuntimeIdentifier"]; + Assert.True(resolvedRid == ""); + } + [Fact] public void PublishSuccessfullyWithRIDRequiringPropertyAndRuntimeIdentifiersNoRuntimeIdentifier() {