Skip to content

Commit cd16c47

Browse files
authored
Merge pull request #29065 from dsplaisted/error-solution-output-path
Add error when specifying --output option for a solution
2 parents 015ca38 + 9d3cd2d commit cd16c47

28 files changed

+421
-220
lines changed

src/Cli/dotnet/OptionForwardingExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ public static class OptionForwardingExtensions
1818

1919
public static ForwardedOption<T> ForwardAsSingle<T>(this ForwardedOption<T> option, Func<T, string> format) => option.SetForwardingFunction(format);
2020

21+
/// <summary>
22+
/// Set up an option to be forwaded as an output path to MSBuild
23+
/// </summary>
24+
/// <param name="option">The command line option</param>
25+
/// <param name="outputPropertyName">The property name for the output path (such as OutputPath or PublishDir)</param>
26+
/// <param name="surroundWithDoubleQuotes">Whether the path should be surrounded with double quotes. This may not be necessary but preserves the provious behavior of "dotnet test"</param>
27+
/// <returns>The option</returns>
28+
public static ForwardedOption<string> ForwardAsOutputPath(this ForwardedOption<string> option, string outputPropertyName, bool surroundWithDoubleQuotes = false)
29+
{
30+
return option.SetForwardingFunction((string o) =>
31+
{
32+
string argVal = CommandDirectoryContext.GetFullPath(o);
33+
if (surroundWithDoubleQuotes)
34+
{
35+
// Not sure if this is necessary, but this is what "dotnet test" previously did and so we are
36+
// preserving the behavior here after refactoring
37+
argVal = TestCommandParser.SurroundWithDoubleQuotes(argVal);
38+
}
39+
return new string[]
40+
{
41+
$"-property:{outputPropertyName}={argVal}",
42+
"-property:_CommandLineDefinedOutputPath=true"
43+
};
44+
});
45+
}
46+
2147
public static ForwardedOption<string[]> ForwardAsProperty(this ForwardedOption<string[]> option) => option
2248
.SetForwardingFunction((optionVals) =>
2349
optionVals

src/Cli/dotnet/commands/dotnet-build/BuildCommandParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal static class BuildCommandParser
2424
public static readonly Option<string> OutputOption = new ForwardedOption<string>(new string[] { "-o", "--output" }, LocalizableStrings.OutputOptionDescription)
2525
{
2626
ArgumentHelpName = LocalizableStrings.OutputOptionName
27-
}.ForwardAsSingle(arg => $"-property:OutputPath={CommandDirectoryContext.GetFullPath(arg)}");
27+
}.ForwardAsOutputPath("OutputPath");
2828

2929
public static readonly Option<bool> NoIncrementalOption = new Option<bool>("--no-incremental", LocalizableStrings.NoIncrementalOptionDescription);
3030

src/Cli/dotnet/commands/dotnet-clean/CleanCommandParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal static class CleanCommandParser
2424
public static readonly Option<string> OutputOption = new ForwardedOption<string>(new string[] { "-o", "--output" }, LocalizableStrings.CmdOutputDirDescription)
2525
{
2626
ArgumentHelpName = LocalizableStrings.CmdOutputDir
27-
}.ForwardAsSingle(o => $"-property:OutputPath={CommandDirectoryContext.GetFullPath(o)}");
27+
}.ForwardAsOutputPath("OutputPath");
2828

2929
public static readonly Option<bool> NoLogoOption = new ForwardedOption<bool>("--nologo", LocalizableStrings.CmdNoLogo)
3030
.ForwardAs("-nologo");

src/Cli/dotnet/commands/dotnet-pack/PackCommandParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal static class PackCommandParser
2424
public static readonly Option<string> OutputOption = new ForwardedOption<string>(new string[] { "-o", "--output" }, LocalizableStrings.CmdOutputDirDescription)
2525
{
2626
ArgumentHelpName = LocalizableStrings.CmdOutputDir
27-
}.ForwardAsSingle(o => $"-property:PackageOutputPath={CommandDirectoryContext.GetFullPath(o)}");
27+
}.ForwardAsOutputPath("PackageOutputPath");
2828

2929
public static readonly Option<bool> NoBuildOption = new ForwardedOption<bool>("--no-build", LocalizableStrings.CmdNoBuildOptionDescription)
3030
.ForwardAs("-property:NoBuild=true");

src/Cli/dotnet/commands/dotnet-publish/PublishCommandParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal static class PublishCommandParser
2525
public static readonly Option<string> OuputOption = new ForwardedOption<string>(new string[] { "-o", "--output" }, LocalizableStrings.OutputOptionDescription)
2626
{
2727
ArgumentHelpName = LocalizableStrings.OutputOption
28-
}.ForwardAsSingle(o => $"-property:PublishDir={CommandDirectoryContext.GetFullPath(o)}");
28+
}.ForwardAsOutputPath("PublishDir");
2929

3030
public static readonly Option<IEnumerable<string>> ManifestOption = new ForwardedOption<IEnumerable<string>>("--manifest", LocalizableStrings.ManifestOptionDescription)
3131
{

src/Cli/dotnet/commands/dotnet-store/StoreCommandParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal static class StoreCommandParser
5454
public static readonly Option<string> OutputOption = new ForwardedOption<string>(new string[] { "-o", "--output" }, LocalizableStrings.OutputOptionDescription)
5555
{
5656
ArgumentHelpName = LocalizableStrings.OutputOption
57-
}.ForwardAsSingle(o => $"-property:ComposeDir={CommandDirectoryContext.GetFullPath(o)}");
57+
}.ForwardAsOutputPath("ComposeDir");
5858

5959
public static readonly Option<string> WorkingDirOption = new ForwardedOption<string>(new string[] { "-w", "--working-dir" }, LocalizableStrings.IntermediateWorkingDirOptionDescription)
6060
{

src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ internal static class TestCommandParser
6161
public static readonly Option<string> OutputOption = new ForwardedOption<string>(new string[] { "-o", "--output" }, LocalizableStrings.CmdOutputDescription)
6262
{
6363
ArgumentHelpName = LocalizableStrings.CmdOutputDir
64-
}.ForwardAsSingle(o => $"-property:OutputPath={SurroundWithDoubleQuotes(CommandDirectoryContext.GetFullPath(o))}");
64+
}
65+
.ForwardAsOutputPath("OutputPath", true);
6566

6667
public static readonly Option<string> DiagOption = new ForwardedOption<string>(new string[] { "-d", "--diag" }, LocalizableStrings.CmdPathTologFileDescription)
6768
{

src/Tasks/Common/Resources/Strings.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,4 +879,8 @@ You may need to build the project on another operating system or architecture, o
879879
<value>NETSDK1193: If PublishSelfContained is set, it must be either true or false. The value given was '{0}'.</value>
880880
<comment>{StrBegin="NETSDK1193: "}</comment>
881881
</data>
882+
<data name="CannotHaveSolutionLevelOutputPath" xml:space="preserve">
883+
<value>NETSDK1194: The "--output" option isn't supported when building a solution.</value>
884+
<comment>{StrBegin="NETSDK1194: "}</comment>
885+
</data>
882886
</root>

src/Tasks/Common/Resources/xlf/Strings.cs.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">NETSDK1099: Publikování do jednoho souboru je podporované jen u spustitelných aplikací.</target>
143143
<note>{StrBegin="NETSDK1099: "}</note>
144144
</trans-unit>
145+
<trans-unit id="CannotHaveSolutionLevelOutputPath">
146+
<source>NETSDK1194: The "--output" option isn't supported when building a solution.</source>
147+
<target state="new">NETSDK1194: The "--output" option isn't supported when building a solution.</target>
148+
<note>{StrBegin="NETSDK1194: "}</note>
149+
</trans-unit>
145150
<trans-unit id="CannotHaveSolutionLevelRuntimeIdentifier">
146151
<source>NETSDK1134: Building a solution with a specific RuntimeIdentifier is not supported. If you would like to publish for a single RID, specifiy the RID at the individual project level instead.</source>
147152
<target state="translated">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ů.</target>

src/Tasks/Common/Resources/xlf/Strings.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">NETSDK1099: Die Veröffentlichung in einer einzelnen Datei wird nur für ausführbare Anwendungen unterstützt.</target>
143143
<note>{StrBegin="NETSDK1099: "}</note>
144144
</trans-unit>
145+
<trans-unit id="CannotHaveSolutionLevelOutputPath">
146+
<source>NETSDK1194: The "--output" option isn't supported when building a solution.</source>
147+
<target state="new">NETSDK1194: The "--output" option isn't supported when building a solution.</target>
148+
<note>{StrBegin="NETSDK1194: "}</note>
149+
</trans-unit>
145150
<trans-unit id="CannotHaveSolutionLevelRuntimeIdentifier">
146151
<source>NETSDK1134: Building a solution with a specific RuntimeIdentifier is not supported. If you would like to publish for a single RID, specifiy the RID at the individual project level instead.</source>
147152
<target state="translated">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 die RID auf individueller Projektebene an.</target>

src/Tasks/Common/Resources/xlf/Strings.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">NETSDK1099: La publicación en un archivo único solo se admite con aplicaciones ejecutables.</target>
143143
<note>{StrBegin="NETSDK1099: "}</note>
144144
</trans-unit>
145+
<trans-unit id="CannotHaveSolutionLevelOutputPath">
146+
<source>NETSDK1194: The "--output" option isn't supported when building a solution.</source>
147+
<target state="new">NETSDK1194: The "--output" option isn't supported when building a solution.</target>
148+
<note>{StrBegin="NETSDK1194: "}</note>
149+
</trans-unit>
145150
<trans-unit id="CannotHaveSolutionLevelRuntimeIdentifier">
146151
<source>NETSDK1134: Building a solution with a specific RuntimeIdentifier is not supported. If you would like to publish for a single RID, specifiy the RID at the individual project level instead.</source>
147152
<target state="translated">NETSDK1134: No se admite la compilación de una solución con un valor RuntimeIdentifier específico. Si quiere publicar para un solo RID, especifique el RID en el nivel de proyecto individual en su lugar.</target>

src/Tasks/Common/Resources/xlf/Strings.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">NETSDK1099: La publication dans un fichier unique n'est prise en charge que pour les applications exécutables.</target>
143143
<note>{StrBegin="NETSDK1099: "}</note>
144144
</trans-unit>
145+
<trans-unit id="CannotHaveSolutionLevelOutputPath">
146+
<source>NETSDK1194: The "--output" option isn't supported when building a solution.</source>
147+
<target state="new">NETSDK1194: The "--output" option isn't supported when building a solution.</target>
148+
<note>{StrBegin="NETSDK1194: "}</note>
149+
</trans-unit>
145150
<trans-unit id="CannotHaveSolutionLevelRuntimeIdentifier">
146151
<source>NETSDK1134: Building a solution with a specific RuntimeIdentifier is not supported. If you would like to publish for a single RID, specifiy the RID at the individual project level instead.</source>
147152
<target state="translated">NETSDK1134: La génération d'une solution avec un RuntimeIdentifier spécifique n'est pas prise en charge. Si vous voulez publier pour un RID unique, spécifiez le RID au niveau du projet individuel à la place.</target>

src/Tasks/Common/Resources/xlf/Strings.it.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">NETSDK1099: la pubblicazione in un singolo file è supportata solo per le applicazioni eseguibili.</target>
143143
<note>{StrBegin="NETSDK1099: "}</note>
144144
</trans-unit>
145+
<trans-unit id="CannotHaveSolutionLevelOutputPath">
146+
<source>NETSDK1194: The "--output" option isn't supported when building a solution.</source>
147+
<target state="new">NETSDK1194: The "--output" option isn't supported when building a solution.</target>
148+
<note>{StrBegin="NETSDK1194: "}</note>
149+
</trans-unit>
145150
<trans-unit id="CannotHaveSolutionLevelRuntimeIdentifier">
146151
<source>NETSDK1134: Building a solution with a specific RuntimeIdentifier is not supported. If you would like to publish for a single RID, specifiy the RID at the individual project level instead.</source>
147152
<target state="translated">NETSDK1134: non è possibile compilare una soluzione con un parametro RuntimeIdentifier specifico. Per pubblicare per un singolo RID, specificare il RID a livello di singolo progetto.</target>

0 commit comments

Comments
 (0)