diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs index 4547a00a730e..518b7c280182 100644 --- a/src/Cli/dotnet/CommonOptions.cs +++ b/src/Cli/dotnet/CommonOptions.cs @@ -176,7 +176,7 @@ public static Option FrameworkOption(string description) => HelpName = CliStrings.FrameworkArgumentName, IsDynamic = true } - .ForwardAsSingle(o => $"--property:TargetFramework={o}") + .ForwardAsMany(o => [$"--property:TargetFramework={o}", "--property:_CommandLineDefinedTargetFramework=true"]) .AddCompletions(CliCompletion.TargetFrameworksFromProjectFile); public static Option ArtifactsPathOption = diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx index 923913bd1f06..bb2674fe2f7b 100644 --- a/src/Tasks/Common/Resources/Strings.resx +++ b/src/Tasks/Common/Resources/Strings.resx @@ -1014,5 +1014,9 @@ You may need to build the project on another operating system or architecture, o NETSDK1234: RoslynCompilerType 'Framework' is deprecated and will be removed in a future version. Please refer to {0} for more information. {StrBegins="NETSDK1234: "}{Locked="RoslynCompilerType"}{Locked="Framework"}{Locked="{0}"} - + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + + diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index e2843aabc896..b91607146ae6 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -182,6 +182,11 @@ NETSDK1134: Vytváření řešení s konkrétním identifikátorem RuntimeIdentifier se nepodporuje. Pokud chcete publikovat pro jedno RID, zadejte místo toho RID na úrovni jednotlivých projektů. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: SupportedOSPlatformVersion {0} nemůže být větší než TargetPlatformVersion {1}. diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index 739552850863..ebe3bfaf35fd 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -182,6 +182,11 @@ NETSDK1134: Das Erstellen einer Lösung mit einem bestimmten RuntimeIdentifier wird nicht unterstützt. Wenn Sie für eine einzelne RID veröffentlichen möchten, geben Sie stattdessen die RID auf der Ebene des einzelnen Projekts an. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: SupportedOSPlatformVersion {0} darf nicht höher sein als TargetPlatformVersion {1}. diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index 05d896c73eec..7aecea3e8f30 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -182,6 +182,11 @@ NETSDK1134: No se admite la creación de una solución con un runtimeIdentifier específico. Si deseas publicar para un único RID, especifica el RID en el nivel de proyecto individual en su lugar. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: El valor de SupportedOSPlatformVersion {0} no puede ser mayor que TargetPlatformVersion {1}. diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index 1e2cb7d74a04..2106c8178d8c 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -182,6 +182,11 @@ NETSDK1134: la création d'une solution avec un RuntimeIdentifier spécifique n'est pas prise en charge. Si vous souhaitez publier pour un seul RID, spécifiez plutôt le RID au niveau du projet individuel. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: le SupportedOSPlatformVersion {0} ne doit pas être supérieur au TargetPlatformVersion {1}. diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index 79345cbc5e59..53cb6334fe3c 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -182,6 +182,11 @@ NETSDK1134: non è supportata la compilazione di una soluzione con un parametro RuntimeIdentifier specifico. Se si desidera pubblicare per un singolo RID, specificare il RID a livello di singolo progetto. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: il valore di SupportedOSPlatformVersion {0} non può essere maggiore di quello di TargetPlatformVersion {1}. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index d59ebf7e4b24..f4e14c6369c0 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -182,6 +182,11 @@ NETSDK1134: 特定の RuntimeIdentifier を使用したソリューションのビルドはサポートされていません。単一の RID に対して発行する場合は、個々のプロジェクト レベルで RID を指定してください。 {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: SupportedOSPlatformVersion {0} を TargetPlatformVersion {1} より大きくすることはできません。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index 5d65dcc1a4f9..29eb57cf1dee 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -182,6 +182,11 @@ NETSDK1134: 특정 RuntimeIdentifier를 사용하여 솔루션을 빌드하는 것은 지원되지 않습니다. 단일 RID에 대해 게시하려는 경우 개별 프로젝트 수준에서 RID를 대신 지정합니다. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: SupportedOSPlatformVersion {0}은(는) TargetPlatformVersion {1}보다 높을 수 없습니다. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index ad7d52f9f803..4b9bc118f22e 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -182,6 +182,11 @@ NETSDK1134: tworzenie rozwiązania z określonym identyfikatorem RuntimeIdentifier nie jest obsługiwane. Jeśli chcesz dokonać publikacji tylko dla jednego identyfikatora RID, określ identyfikator RID na poziomie projektu indywidualnego. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: Element SupportedOSPlatformVersion {0} nie może być większy niż element TargetPlatformVersion {1}. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index 2d944e7b5097..ace61bda457c 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -182,6 +182,11 @@ NETSDK1134: Não há suporte para a criação de uma solução com um RuntimeIdentifier específico. Se você quiser publicar para um único RID, especifique o RID no nível do projeto individual. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: SupportedOSPlatformVersion {0} não pode ser superior a TargetPlatformVersion {1}. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index 8c38a2f4519c..06393535c9c0 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -182,6 +182,11 @@ NETSDK1134: сборка решения с заданным идентификатором RuntimeIdentifier не поддерживается. Если вы хотите выполнить публикацию для одного RID, укажите RID на уровне отдельного проекта. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: версия SupportedOSPlatformVersion {0} не может быть выше версии TargetPlatformVersion {1}. diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index a8e1b13f931a..8ff20aecaf08 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -182,6 +182,11 @@ NETSDK1134: Belirli bir RuntimeIdentifier ile bir çözüm oluşturma desteklenmiyor. Tek bir RID için yayımlamak istiyorsanız, bunun yerine ilgili proje düzeyindeki RID'yi belirtin. {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: {0} SupportedOSPlatformVersion, {1} TargetPlatformVersion değerinden yüksek olamaz. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index 05fa79d313cf..22df29d24bae 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -182,6 +182,11 @@ NETSDK1134: 不支持使用特定 RuntimeIdentifier 生成解决方案。如果要为单个 RID 发布,请改为在单独的项目级别指定 RID。 {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: SupportedOSPlatformVersion {0} 不能高于 TargetPlatformVersion {1}。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index 6ed44c157d07..5243712d792d 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -182,6 +182,11 @@ NETSDK1134: 不支援使用特定 RuntimeIdentifier 建置解決方案。若要發佈單一 RID,請改為在個別專案層級指定 RID。 {StrBegins="NETSDK1134: "} + + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + NETSDK1235: The "--framework" option isn't recommended when building a solution. Specifying a solution-level framework results in all projects building for that framework, which can cause referenced projects to build multiple times and can lead to inconsistent builds. + {StrBegins="NETSDK1235: "}{Locked="--framework"} + NETSDK1135: SupportedOSPlatformVersion {0} cannot be higher than TargetPlatformVersion {1}. NETSDK1135: SupportedOSPlatformVersion {0} 不得高於 TargetPlatformVersion {1}。 diff --git a/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions-ver/SolutionFile/ImportAfter/Microsoft.NET.Sdk.Solution.targets b/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions-ver/SolutionFile/ImportAfter/Microsoft.NET.Sdk.Solution.targets index 3cb04c4b9959..ead655947a0a 100644 --- a/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions-ver/SolutionFile/ImportAfter/Microsoft.NET.Sdk.Solution.targets +++ b/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions-ver/SolutionFile/ImportAfter/Microsoft.NET.Sdk.Solution.targets @@ -37,4 +37,24 @@ Copyright (c) .NET Foundation. All rights reserved. + + + + + + + diff --git a/test/dotnet.Tests/FrameworkOptionTests.cs b/test/dotnet.Tests/FrameworkOptionTests.cs new file mode 100644 index 000000000000..00f24c8567c4 --- /dev/null +++ b/test/dotnet.Tests/FrameworkOptionTests.cs @@ -0,0 +1,85 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System.Runtime.CompilerServices; + +namespace dotnet.Tests +{ + public class FrameworkOptionTests : SdkTest + { + public FrameworkOptionTests(ITestOutputHelper log) : base(log) + { + } + + [Theory] + [InlineData("build", true)] + [InlineData("clean", true)] + [InlineData("publish", true)] + [InlineData("test", true)] + public void FrameworkOptionGeneratesWarningsWithSolutionFiles(string command, bool shouldWarn) + { + TestFrameworkWithSolution(command, useOption: true, shouldWarn: shouldWarn); + } + + [Theory] + [InlineData("build")] + [InlineData("clean")] + [InlineData("publish")] + [InlineData("test")] + public void TargetFrameworkPropertyDoesNotGenerateWarningsWithSolutionFiles(string command) + { + TestFrameworkWithSolution(command, useOption: false, shouldWarn: false); + } + + void TestFrameworkWithSolution(string command, bool useOption, bool shouldWarn, [CallerMemberName] string callingMethod = "") + { + var testProject = new TestProject() + { + IsExe = true, + TargetFrameworks = ToolsetInfo.CurrentTargetFramework + }; + + var testAsset = _testAssetsManager.CreateTestProject(testProject, callingMethod, identifier: command); + + var slnDirectory = testAsset.TestRoot; + + Log.WriteLine($"Test root: {slnDirectory}"); + + new DotnetNewCommand(Log) + .WithVirtualHive() + .WithWorkingDirectory(slnDirectory) + .Execute("sln") + .Should().Pass(); + + new DotnetCommand(Log) + .WithWorkingDirectory(slnDirectory) + .Execute("sln", "add", testProject.Name) + .Should().Pass(); + + Microsoft.DotNet.Cli.Utils.CommandResult commandResult; + if (useOption) + { + commandResult = new DotnetCommand(Log) + .WithWorkingDirectory(slnDirectory) + .Execute(command, "--framework", ToolsetInfo.CurrentTargetFramework); + } + else + { + commandResult = new DotnetCommand(Log) + .WithWorkingDirectory(slnDirectory) + .Execute(command, $"--property:TargetFramework={ToolsetInfo.CurrentTargetFramework}"); + } + commandResult.Should().Pass(); + if (shouldWarn) + { + commandResult.Should().HaveStdOutContaining("NETSDK1235"); + } + else + { + commandResult.Should().NotHaveStdOutContaining("NETSDK1235"); + } + } + } +}