Skip to content

Commit

Permalink
Make dotnet publish use Release by default in 8.0+ Projects (#29155)
Browse files Browse the repository at this point in the history
  • Loading branch information
nagilson committed Jan 27, 2023
2 parents 33d4e69 + d6e4e38 commit 7f685ff
Show file tree
Hide file tree
Showing 53 changed files with 1,646 additions and 3,162 deletions.
7 changes: 0 additions & 7 deletions src/Cli/dotnet/CommonLocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,6 @@
<data name="ToolSettingsUnsupportedRunner" xml:space="preserve">
<value>Command '{0}' uses unsupported runner '{1}'."</value>
</data>
<data name="SolutionExecutableConfigurationMismatchError" xml:space="preserve">
<value>Multiple executable projects in the solution contain conflicting '{0}' values. Ensure the values match. Consider using a Directory.build.props file to set all project configurations. Conflicting projects:
{1}.</value>
</data>
<data name="ShellShimConflict" xml:space="preserve">
<value>Command '{0}' conflicts with an existing command from another tool.</value>
</data>
Expand Down Expand Up @@ -709,9 +705,6 @@ The default is 'true' if a runtime identifier is specified.</value>
<data name="ResponseFileNotFound" xml:space="preserve">
<value>Response file '{0}' does not exist.</value>
</data>
<data name="CustomConfigurationDisablesPublishAndPackReleaseProperties" xml:space="preserve">
<value>A custom configuration was detected in the project '{0}', so the property '{1}' will not take effect.</value>
</data>
<data name="CorruptSolutionProjectFolderStructure" xml:space="preserve">
<value>The solution file '{0}' is missing EndProject tags or has invalid child-parent project folder mappings around project GUID: '{1}'. Manually repair the solution or try to open and save it in Visual Studio."</value>
</data>
Expand Down
271 changes: 181 additions & 90 deletions src/Cli/dotnet/ReleasePropertyProjectLocator.cs

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions src/Cli/dotnet/commands/dotnet-pack/PackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.CommandLine.Parsing;
using Microsoft.DotNet.Tools.Publish;
using System.Linq;
using System.Diagnostics;

namespace Microsoft.DotNet.Tools.Pack
{
Expand Down Expand Up @@ -37,15 +38,21 @@ public static PackCommand FromParseResult(ParseResult parseResult, string msbuil
var msbuildArgs = new List<string>()
{
"-target:pack",
"--property:_IsPacking=true"
"--property:_IsPacking=true" // This property will not hold true for MSBuild /t:Publish or in VS.
};

IEnumerable<string> slnOrProjectArgs = parseResult.GetValue(PackCommandParser.SlnOrProjectArgument);

msbuildArgs.AddRange(parseResult.OptionValuesToBeForwarded(PackCommandParser.GetCommand()));
ReleasePropertyProjectLocator projectLocator = new ReleasePropertyProjectLocator(Environment.GetEnvironmentVariable(EnvironmentVariableNames.ENABLE_PACK_RELEASE_FOR_SOLUTIONS) != null);
msbuildArgs.AddRange(projectLocator.GetCustomDefaultConfigurationValueIfSpecified(parseResult, MSBuildPropertyNames.PACK_RELEASE,
slnOrProjectArgs, PackCommandParser.ConfigurationOption) ?? Array.Empty<string>());

ReleasePropertyProjectLocator projectLocator = new ReleasePropertyProjectLocator(parseResult, MSBuildPropertyNames.PACK_RELEASE,
new ReleasePropertyProjectLocator.DependentCommandOptions(
parseResult.GetValue(PackCommandParser.SlnOrProjectArgument),
parseResult.HasOption(PackCommandParser.ConfigurationOption) ? parseResult.GetValue(PackCommandParser.ConfigurationOption) : null
)
);
msbuildArgs.AddRange(projectLocator.GetCustomDefaultConfigurationValueIfSpecified());

msbuildArgs.AddRange(slnOrProjectArgs ?? Array.Empty<string>());

bool noRestore = parseResult.HasOption(PackCommandParser.NoRestoreOption) || parseResult.HasOption(PackCommandParser.NoBuildOption);
Expand Down
15 changes: 11 additions & 4 deletions src/Cli/dotnet/commands/dotnet-publish/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static PublishCommand FromParseResult(ParseResult parseResult, string msb
var msbuildArgs = new List<string>()
{
"-target:Publish",
"--property:_IsPublishing=true" // This property will not hold true for MSBuild /t:Publish. VS should also inject this property when publishing in the future.
"--property:_IsPublishing=true" // This property will not hold true for MSBuild /t:Publish or in VS.
};

IEnumerable<string> slnOrProjectArgs = parseResult.GetValue(PublishCommandParser.SlnOrProjectArgument);
Expand All @@ -55,9 +55,16 @@ public static PublishCommand FromParseResult(ParseResult parseResult, string msb
parseResult.HasOption(PublishCommandParser.NoSelfContainedOption));

msbuildArgs.AddRange(parseResult.OptionValuesToBeForwarded(PublishCommandParser.GetCommand()));
ReleasePropertyProjectLocator projectLocator = new ReleasePropertyProjectLocator(Environment.GetEnvironmentVariable(EnvironmentVariableNames.ENABLE_PUBLISH_RELEASE_FOR_SOLUTIONS) != null);
msbuildArgs.AddRange(projectLocator.GetCustomDefaultConfigurationValueIfSpecified(parseResult, MSBuildPropertyNames.PUBLISH_RELEASE,
slnOrProjectArgs, PublishCommandParser.ConfigurationOption) ?? Array.Empty<string>());

ReleasePropertyProjectLocator projectLocator = new ReleasePropertyProjectLocator(parseResult, MSBuildPropertyNames.PUBLISH_RELEASE,
new ReleasePropertyProjectLocator.DependentCommandOptions(
parseResult.GetValue(PublishCommandParser.SlnOrProjectArgument),
parseResult.HasOption(PublishCommandParser.ConfigurationOption) ? parseResult.GetValue(PublishCommandParser.ConfigurationOption) : null,
parseResult.HasOption(PublishCommandParser.FrameworkOption) ? parseResult.GetValue(PublishCommandParser.FrameworkOption) : null
)
);
msbuildArgs.AddRange(projectLocator.GetCustomDefaultConfigurationValueIfSpecified());

msbuildArgs.AddRange(slnOrProjectArgs ?? Array.Empty<string>());

bool noRestore = parseResult.HasOption(PublishCommandParser.NoRestoreOption)
Expand Down
1 change: 1 addition & 0 deletions src/Cli/dotnet/dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<EmbeddedResource Update="ToolManifest\*.resx" Namespace="Microsoft.DotNet.ToolManifest" />
<EmbeddedResource Update="NugetSearch\*.resx" Namespace="Microsoft.DotNet.NugetSearch" />
<EmbeddedResource Update="NugetPackageDownloader\*.resx" Namespace="Microsoft.DotNet.Cli.NuGetPackageDownloader" />
<EmbeddedResource Include="$(RepoRoot)src\Tasks\Common\Resources\Strings.resx" LinkBase="Resources" GenerateSource="True" Namespace="Microsoft.NET.Build.Tasks" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Microsoft.DotNet.Configurer/Microsoft.DotNet.Configurer.csproj" />
Expand Down
12 changes: 0 additions & 12 deletions src/Cli/dotnet/xlf/CommonLocalizableStrings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">V {0} se nenašel žádný projekt.</target>
<note />
</trans-unit>
<trans-unit id="CustomConfigurationDisablesPublishAndPackReleaseProperties">
<source>A custom configuration was detected in the project '{0}', so the property '{1}' will not take effect.</source>
<target state="translated">U projektu {0} byla zjištěna vlastní konfigurace, takže vlastnost {1} se neprojeví.</target>
<note />
</trans-unit>
<trans-unit id="DisableBuildServersOptionDescription">
<source>Force the command to ignore any persistent build servers.</source>
<target state="translated">Vynuťte, aby příkaz ignoroval všechny trvalé buildovací servery.</target>
Expand Down Expand Up @@ -202,13 +197,6 @@ Pokud se zadá identifikátor modulu runtime, výchozí hodnota je true.</target
<target state="translated">Řešení</target>
<note />
</trans-unit>
<trans-unit id="SolutionExecutableConfigurationMismatchError">
<source>Multiple executable projects in the solution contain conflicting '{0}' values. Ensure the values match. Consider using a Directory.build.props file to set all project configurations. Conflicting projects:
{1}.</source>
<target state="translated">Několik spustitelných projektů v řešení obsahuje konfliktní hodnoty {0}. Ujistěte se, že se hodnoty shodují. Zvažte použití souboru Directory.build.props k nastavení všech konfigurací projektu. Konfliktní projekty:
{1}.</target>
<note />
</trans-unit>
<trans-unit id="SolutionFile">
<source>Solution file</source>
<target state="translated">Soubor řešení</target>
Expand Down
12 changes: 0 additions & 12 deletions src/Cli/dotnet/xlf/CommonLocalizableStrings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">In "{0}" wurde kein Projekt gefunden.</target>
<note />
</trans-unit>
<trans-unit id="CustomConfigurationDisablesPublishAndPackReleaseProperties">
<source>A custom configuration was detected in the project '{0}', so the property '{1}' will not take effect.</source>
<target state="translated">Im Projekt „{0}“ wurde eine benutzerdefinierte Konfiguration erkannt, somit wird die Eigenschaft „{1}“ nicht wirksam.</target>
<note />
</trans-unit>
<trans-unit id="DisableBuildServersOptionDescription">
<source>Force the command to ignore any persistent build servers.</source>
<target state="translated">Erzwingen Sie, dass der Befehl alle persistenten Buildserver ignoriert.</target>
Expand Down Expand Up @@ -202,13 +197,6 @@ Der Standardwert lautet TRUE, wenn eine Runtime-ID angegeben wird.</target>
<target state="translated">Projektmappe</target>
<note />
</trans-unit>
<trans-unit id="SolutionExecutableConfigurationMismatchError">
<source>Multiple executable projects in the solution contain conflicting '{0}' values. Ensure the values match. Consider using a Directory.build.props file to set all project configurations. Conflicting projects:
{1}.</source>
<target state="translated">Mehrere ausführbare Projekte in der Lösung enthalten widersprüchliche Werte für „{0}“. Stellen Sie sicher, dass die Werte übereinstimmen. Erwägen Sie die Verwendung einer Datei „Directory.build.props“, um alle Projektkonfigurationen festzulegen. In Konflikt stehende Projekte:
{1}.</target>
<note />
</trans-unit>
<trans-unit id="SolutionFile">
<source>Solution file</source>
<target state="translated">Projektmappendatei</target>
Expand Down
12 changes: 0 additions & 12 deletions src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">No se encuentra ningún proyecto en "{0}".</target>
<note />
</trans-unit>
<trans-unit id="CustomConfigurationDisablesPublishAndPackReleaseProperties">
<source>A custom configuration was detected in the project '{0}', so the property '{1}' will not take effect.</source>
<target state="translated">Se detectó una configuración personalizada en el proyecto "{0}", por lo que la propiedad "{1}" no surtirá efecto.</target>
<note />
</trans-unit>
<trans-unit id="DisableBuildServersOptionDescription">
<source>Force the command to ignore any persistent build servers.</source>
<target state="translated">Fuerce el comando para omitir los servidores de compilación persistentes.</target>
Expand Down Expand Up @@ -202,13 +197,6 @@ El valor predeterminado es "true" si se especifica un identificador de entorno d
<target state="translated">Solución</target>
<note />
</trans-unit>
<trans-unit id="SolutionExecutableConfigurationMismatchError">
<source>Multiple executable projects in the solution contain conflicting '{0}' values. Ensure the values match. Consider using a Directory.build.props file to set all project configurations. Conflicting projects:
{1}.</source>
<target state="translated">Varios proyectos ejecutables de la solución contienen valores "{0}" en conflicto. Asegúrese de que los valores coinciden. Considere la posibilidad de usar un archivo Directory.build.props para establecer todas las configuraciones del proyecto. Proyectos en conflicto:
{1}.</target>
<note />
</trans-unit>
<trans-unit id="SolutionFile">
<source>Solution file</source>
<target state="translated">Archivo de solución</target>
Expand Down
12 changes: 0 additions & 12 deletions src/Cli/dotnet/xlf/CommonLocalizableStrings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">Projet introuvable dans '{0}'.</target>
<note />
</trans-unit>
<trans-unit id="CustomConfigurationDisablesPublishAndPackReleaseProperties">
<source>A custom configuration was detected in the project '{0}', so the property '{1}' will not take effect.</source>
<target state="translated">Une configuration personnalisée a été détectée dans le '{0}' du projet, la propriété '{1}' ne sera donc pas prise en compte.</target>
<note />
</trans-unit>
<trans-unit id="DisableBuildServersOptionDescription">
<source>Force the command to ignore any persistent build servers.</source>
<target state="translated">Forcez la commande à ignorer tous les serveurs de build persistants.</target>
Expand Down Expand Up @@ -202,13 +197,6 @@ La valeur par défaut est 'true' si un identificateur de runtime est spécifié.
<target state="translated">Solution</target>
<note />
</trans-unit>
<trans-unit id="SolutionExecutableConfigurationMismatchError">
<source>Multiple executable projects in the solution contain conflicting '{0}' values. Ensure the values match. Consider using a Directory.build.props file to set all project configurations. Conflicting projects:
{1}.</source>
<target state="translated">Plusieurs projets exécutables de la solution contiennent des valeurs de '{0}' en conflit. Vérifiez que les valeurs correspondent. Utilisez un fichier Directory.build.props pour définir toutes les configurations de projet. Projets en conflit :
{1}.</target>
<note />
</trans-unit>
<trans-unit id="SolutionFile">
<source>Solution file</source>
<target state="translated">Fichier solution</target>
Expand Down
12 changes: 0 additions & 12 deletions src/Cli/dotnet/xlf/CommonLocalizableStrings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">Non è stato trovato alcun progetto in `{0}`.</target>
<note />
</trans-unit>
<trans-unit id="CustomConfigurationDisablesPublishAndPackReleaseProperties">
<source>A custom configuration was detected in the project '{0}', so the property '{1}' will not take effect.</source>
<target state="translated">È stata rilevata una configurazione personalizzata nel progetto '{0}', quindi la proprietà '{1}' non avrà effetto.</target>
<note />
</trans-unit>
<trans-unit id="DisableBuildServersOptionDescription">
<source>Force the command to ignore any persistent build servers.</source>
<target state="translated">Forza il comando a ignorare tutti i server di compilazione persistenti.</target>
Expand Down Expand Up @@ -202,13 +197,6 @@ L'impostazione predefinita è 'true' se si specifica un identificatore di runtim
<target state="translated">Soluzione</target>
<note />
</trans-unit>
<trans-unit id="SolutionExecutableConfigurationMismatchError">
<source>Multiple executable projects in the solution contain conflicting '{0}' values. Ensure the values match. Consider using a Directory.build.props file to set all project configurations. Conflicting projects:
{1}.</source>
<target state="translated">Più progetti eseguibili nella soluzione contengono valori '{0}' in conflitto. Verificare che i valori corrispondano. Prova a usare un file Directory.build.props per impostare tutte le configurazioni del progetto. Progetti in conflitto:
{1}.</target>
<note />
</trans-unit>
<trans-unit id="SolutionFile">
<source>Solution file</source>
<target state="translated">File di soluzione</target>
Expand Down
12 changes: 0 additions & 12 deletions src/Cli/dotnet/xlf/CommonLocalizableStrings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">`{0}` にプロジェクトが見つかりませんでした。</target>
<note />
</trans-unit>
<trans-unit id="CustomConfigurationDisablesPublishAndPackReleaseProperties">
<source>A custom configuration was detected in the project '{0}', so the property '{1}' will not take effect.</source>
<target state="translated">プロジェクト '{0}' でカスタム構成が検出されたため、プロパティ '{1}' は有効になりません。</target>
<note />
</trans-unit>
<trans-unit id="DisableBuildServersOptionDescription">
<source>Force the command to ignore any persistent build servers.</source>
<target state="translated">永続的なビルド サーバーがそのコマンドで無視されるようにします。</target>
Expand Down Expand Up @@ -202,13 +197,6 @@ The default is 'true' if a runtime identifier is specified.</source>
<target state="translated">ソリューション</target>
<note />
</trans-unit>
<trans-unit id="SolutionExecutableConfigurationMismatchError">
<source>Multiple executable projects in the solution contain conflicting '{0}' values. Ensure the values match. Consider using a Directory.build.props file to set all project configurations. Conflicting projects:
{1}.</source>
<target state="translated">ソリューション内の複数の実行可能プロジェクトに、競合する '{0}' 値が含まれています。値が一致するようにしてください。Directory.build.props ファイルを使用して、すべてのプロジェクト構成を設定することを検討してください。競合するプロジェクト:
{1}。</target>
<note />
</trans-unit>
<trans-unit id="SolutionFile">
<source>Solution file</source>
<target state="translated">ソリューション ファイル</target>
Expand Down
12 changes: 0 additions & 12 deletions src/Cli/dotnet/xlf/CommonLocalizableStrings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">'{0}'에서 프로젝트를 찾을 수 없습니다.</target>
<note />
</trans-unit>
<trans-unit id="CustomConfigurationDisablesPublishAndPackReleaseProperties">
<source>A custom configuration was detected in the project '{0}', so the property '{1}' will not take effect.</source>
<target state="translated">'{0}' 프로젝트에서 사용자 지정 구성이 검색되었으므로 '{1}' 속성이 적용되지 않습니다.</target>
<note />
</trans-unit>
<trans-unit id="DisableBuildServersOptionDescription">
<source>Force the command to ignore any persistent build servers.</source>
<target state="translated">모든 영구 빌드 서버를 무시하도록 명령을 강제 실행합니다.</target>
Expand Down Expand Up @@ -202,13 +197,6 @@ The default is 'true' if a runtime identifier is specified.</source>
<target state="translated">솔루션</target>
<note />
</trans-unit>
<trans-unit id="SolutionExecutableConfigurationMismatchError">
<source>Multiple executable projects in the solution contain conflicting '{0}' values. Ensure the values match. Consider using a Directory.build.props file to set all project configurations. Conflicting projects:
{1}.</source>
<target state="translated">솔루션의 여러 실행 가능한 프로젝트에 충돌하는 '{0}' 값이 포함되어 있습니다. 값이 일치하는지 확인하세요. Directory.build.props 파일을 사용하여 모든 프로젝트 구성을 설정하는 것이 좋습니다. 충돌하는 프로젝트:
{1}.</target>
<note />
</trans-unit>
<trans-unit id="SolutionFile">
<source>Solution file</source>
<target state="translated">솔루션 파일</target>
Expand Down
Loading

0 comments on commit 7f685ff

Please sign in to comment.