diff --git a/src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs b/src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs index fed37d16133..de11124f2d9 100644 --- a/src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs +++ b/src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs @@ -422,6 +422,47 @@ public void PreprocessSwitchIdentificationTests(string preprocess) unquoteParameters.ShouldBeTrue(); } + [Theory] + [InlineData("targets")] + [InlineData("tArGeTs")] + [InlineData("ts")] + public void TargetsSwitchIdentificationTests(string @switch) + { + CommandLineSwitches.IsParameterizedSwitch( + @switch, + out var parameterizedSwitch, + out var duplicateSwitchErrorMessage, + out var multipleParametersAllowed, + out var missingParametersErrorMessage, + out var unquoteParameters, + out var emptyParametersAllowed).ShouldBeTrue(); + parameterizedSwitch.ShouldBe(CommandLineSwitches.ParameterizedSwitch.Targets); + duplicateSwitchErrorMessage.ShouldBeNull(); + multipleParametersAllowed.ShouldBeFalse(); + missingParametersErrorMessage.ShouldBeNull(); + unquoteParameters.ShouldBeTrue(); + emptyParametersAllowed.ShouldBeFalse(); + } + + [Fact] + public void TargetsSwitchParameter() + { + CommandLineSwitches switches = new CommandLineSwitches(); + MSBuildApp.GatherCommandLineSwitches(new ArrayList() { "/targets:targets.txt" }, switches); + + switches.HaveErrors().ShouldBeFalse(); + switches[CommandLineSwitches.ParameterizedSwitch.Targets].ShouldBe(new[] { "targets.txt" }); + } + + [Fact] + public void TargetsSwitchDoesNotSupportMultipleOccurrences() + { + CommandLineSwitches switches = new CommandLineSwitches(); + MSBuildApp.GatherCommandLineSwitches(new ArrayList() { "/targets /targets" }, switches); + + switches.HaveErrors().ShouldBeTrue(); + } + [Theory] [InlineData("isolate")] [InlineData("ISOLATE")] @@ -894,6 +935,7 @@ public void InvalidToolsVersionErrors() 1, true, new StringWriter(), + new StringWriter(), false, warningsAsErrors: null, warningsAsMessages: null, diff --git a/src/MSBuild/CommandLineSwitches.cs b/src/MSBuild/CommandLineSwitches.cs index 7737542607f..e986b475459 100644 --- a/src/MSBuild/CommandLineSwitches.cs +++ b/src/MSBuild/CommandLineSwitches.cs @@ -93,6 +93,7 @@ internal enum ParameterizedSwitch FileLoggerParameters9, NodeReuse, Preprocess, + Targets, WarningsAsErrors, WarningsAsMessages, BinaryLogger, @@ -261,6 +262,7 @@ bool emptyParametersAllowed new ParameterizedSwitchInfo( new string[] { "fileloggerparameters9", "flp9" }, ParameterizedSwitch.FileLoggerParameters9, null, false, "MissingFileLoggerParameterError", true, false ), new ParameterizedSwitchInfo( new string[] { "nodereuse", "nr" }, ParameterizedSwitch.NodeReuse, null, false, "MissingNodeReuseParameterError", true, false ), new ParameterizedSwitchInfo( new string[] { "preprocess", "pp" }, ParameterizedSwitch.Preprocess, null, false, null, true, false ), + new ParameterizedSwitchInfo( new string[] { "targets", "ts" }, ParameterizedSwitch.Targets, null, false, null, true, false ), new ParameterizedSwitchInfo( new string[] { "warnaserror", "err" }, ParameterizedSwitch.WarningsAsErrors, null, true, null, true, true ), new ParameterizedSwitchInfo( new string[] { "warnasmessage", "nowarn" }, ParameterizedSwitch.WarningsAsMessages, null, true, "MissingWarnAsMessageParameterError", true, false ), new ParameterizedSwitchInfo( new string[] { "binarylogger", "bl" }, ParameterizedSwitch.BinaryLogger, null, false, null, true, false ), diff --git a/src/MSBuild/Resources/Strings.resx b/src/MSBuild/Resources/Strings.resx index a6cb946ecda..69cbcd118b2 100644 --- a/src/MSBuild/Resources/Strings.resx +++ b/src/MSBuild/Resources/Strings.resx @@ -790,6 +790,22 @@ Copyright (C) Microsoft Corporation. All rights reserved. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + MSBUILD : Configuration error MSB1043: The application could not start. {0} @@ -1157,6 +1173,10 @@ Copyright (C) Microsoft Corporation. All rights reserved. MSBUILD : error MSB1047: File to preprocess to is not valid. {0} {StrBegin="MSBUILD : error MSB1047: "} + + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1021: Cannot create an instance of the logger. {0} @@ -1232,7 +1252,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. diff --git a/src/MSBuild/Resources/xlf/Strings.cs.xlf b/src/MSBuild/Resources/xlf/Strings.cs.xlf index 8cee3f48a01..187bec992eb 100644 --- a/src/MSBuild/Resources/xlf/Strings.cs.xlf +++ b/src/MSBuild/Resources/xlf/Strings.cs.xlf @@ -178,6 +178,31 @@ Copyright (C) Microsoft Corporation. Všechna práva vyhrazena. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1227,6 +1252,11 @@ Copyright (C) Microsoft Corporation. Všechna práva vyhrazena. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: Pro tento přepínač se nepoužívají žádné parametry. diff --git a/src/MSBuild/Resources/xlf/Strings.de.xlf b/src/MSBuild/Resources/xlf/Strings.de.xlf index 5f840b87545..33a04bfe27c 100644 --- a/src/MSBuild/Resources/xlf/Strings.de.xlf +++ b/src/MSBuild/Resources/xlf/Strings.de.xlf @@ -178,6 +178,31 @@ Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1219,6 +1244,11 @@ Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: Der Schalter erlaubt keine Parameter. diff --git a/src/MSBuild/Resources/xlf/Strings.en.xlf b/src/MSBuild/Resources/xlf/Strings.en.xlf index ac3e246bfa7..54831323f57 100644 --- a/src/MSBuild/Resources/xlf/Strings.en.xlf +++ b/src/MSBuild/Resources/xlf/Strings.en.xlf @@ -188,6 +188,31 @@ Copyright (C) Microsoft Corporation. All rights reserved. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1408,6 +1433,11 @@ Copyright (C) Microsoft Corporation. All rights reserved. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: This switch does not take any parameters. diff --git a/src/MSBuild/Resources/xlf/Strings.es.xlf b/src/MSBuild/Resources/xlf/Strings.es.xlf index 044bd41ec27..8ceb302dd0e 100644 --- a/src/MSBuild/Resources/xlf/Strings.es.xlf +++ b/src/MSBuild/Resources/xlf/Strings.es.xlf @@ -178,6 +178,31 @@ Copyright (C) Microsoft Corporation. Todos los derechos reservados. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1228,6 +1253,11 @@ Copyright (C) Microsoft Corporation. Todos los derechos reservados. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: Este modificador no tiene ningún parámetro. diff --git a/src/MSBuild/Resources/xlf/Strings.fr.xlf b/src/MSBuild/Resources/xlf/Strings.fr.xlf index 5060ed642cc..90bcbfb3912 100644 --- a/src/MSBuild/Resources/xlf/Strings.fr.xlf +++ b/src/MSBuild/Resources/xlf/Strings.fr.xlf @@ -178,6 +178,31 @@ Copyright (C) Microsoft Corporation. Tous droits réservés. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1220,6 +1245,11 @@ Copyright (C) Microsoft Corporation. Tous droits réservés. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: Ce commutateur n'accepte aucun paramètre. diff --git a/src/MSBuild/Resources/xlf/Strings.it.xlf b/src/MSBuild/Resources/xlf/Strings.it.xlf index de76b068d06..842f9f7358f 100644 --- a/src/MSBuild/Resources/xlf/Strings.it.xlf +++ b/src/MSBuild/Resources/xlf/Strings.it.xlf @@ -185,6 +185,31 @@ Copyright (C) Microsoft Corporation. Tutti i diritti sono riservati. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1240,6 +1265,11 @@ Copyright (C) Microsoft Corporation. Tutti i diritti sono riservati. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: questa opzione non accetta parametri. diff --git a/src/MSBuild/Resources/xlf/Strings.ja.xlf b/src/MSBuild/Resources/xlf/Strings.ja.xlf index b9f0c0b05c5..dded98303db 100644 --- a/src/MSBuild/Resources/xlf/Strings.ja.xlf +++ b/src/MSBuild/Resources/xlf/Strings.ja.xlf @@ -178,6 +178,31 @@ Copyright (C) Microsoft Corporation.All rights reserved. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1219,6 +1244,11 @@ Copyright (C) Microsoft Corporation.All rights reserved. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: このスイッチにはパラメーターを指定できません。 diff --git a/src/MSBuild/Resources/xlf/Strings.ko.xlf b/src/MSBuild/Resources/xlf/Strings.ko.xlf index 1524e245cd5..f7c9e9d83c5 100644 --- a/src/MSBuild/Resources/xlf/Strings.ko.xlf +++ b/src/MSBuild/Resources/xlf/Strings.ko.xlf @@ -178,6 +178,31 @@ Copyright (C) Microsoft Corporation. All rights reserved. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1219,6 +1244,11 @@ Copyright (C) Microsoft Corporation. All rights reserved. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: 이 스위치에는 매개 변수를 지정할 수 없습니다. diff --git a/src/MSBuild/Resources/xlf/Strings.pl.xlf b/src/MSBuild/Resources/xlf/Strings.pl.xlf index f5d5c466236..b42f354646d 100644 --- a/src/MSBuild/Resources/xlf/Strings.pl.xlf +++ b/src/MSBuild/Resources/xlf/Strings.pl.xlf @@ -185,6 +185,31 @@ Copyright (C) Microsoft Corporation. Wszelkie prawa zastrzeżone. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1232,6 +1257,11 @@ Copyright (C) Microsoft Corporation. Wszelkie prawa zastrzeżone. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: ten przełącznik nie ma żadnych parametrów. diff --git a/src/MSBuild/Resources/xlf/Strings.pt-BR.xlf b/src/MSBuild/Resources/xlf/Strings.pt-BR.xlf index 9acf7772cfd..d62dccfaf1e 100644 --- a/src/MSBuild/Resources/xlf/Strings.pt-BR.xlf +++ b/src/MSBuild/Resources/xlf/Strings.pt-BR.xlf @@ -179,6 +179,31 @@ isoladamente. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1220,6 +1245,11 @@ isoladamente. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: Esta opção não aceita parâmetros. diff --git a/src/MSBuild/Resources/xlf/Strings.ru.xlf b/src/MSBuild/Resources/xlf/Strings.ru.xlf index b24b9e42bdc..7208572366e 100644 --- a/src/MSBuild/Resources/xlf/Strings.ru.xlf +++ b/src/MSBuild/Resources/xlf/Strings.ru.xlf @@ -177,6 +177,31 @@ Copyright (C) Microsoft Corporation. All rights reserved. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1219,6 +1244,11 @@ Copyright (C) Microsoft Corporation. All rights reserved. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: у этого ключа нет параметров. diff --git a/src/MSBuild/Resources/xlf/Strings.tr.xlf b/src/MSBuild/Resources/xlf/Strings.tr.xlf index 3b990dbc6d3..534daca3b7a 100644 --- a/src/MSBuild/Resources/xlf/Strings.tr.xlf +++ b/src/MSBuild/Resources/xlf/Strings.tr.xlf @@ -178,6 +178,31 @@ Telif Hakkı (C) Microsoft Corporation. Tüm hakları saklıdır. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1223,6 +1248,11 @@ Telif Hakkı (C) Microsoft Corporation. Tüm hakları saklıdır. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: Bu anahtar parametreyle kullanılmaz. diff --git a/src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf b/src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf index 789910950e1..066dc627c2b 100644 --- a/src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf @@ -178,6 +178,31 @@ Copyright (C) Microsoft Corporation. All rights reserved. For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1219,6 +1244,11 @@ Copyright (C) Microsoft Corporation. All rights reserved. that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: 此开关不采用任何参数。 diff --git a/src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf b/src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf index 8eed5bab848..d4905ca2b9b 100644 --- a/src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf @@ -178,6 +178,31 @@ Copyright (C) Microsoft Corporation. 著作權所有,並保留一切權利。 For more detailed information, see https://aka.ms/msbuild/docs + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + -targets[:file] + Prints a list of available targets without executing the + actual build process. By default the output is written to + the console window. If the path to an output file + is provided that will be used instead. + (Short form: -ts) + Example: + -ts:out.txt + + + LOCALIZATION: "MSBuild" should not be localized. + LOCALIZATION: "-targets" and "-ts" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + Switches: Note that you can specify switches using both "-switch" and "/switch". @@ -1219,6 +1244,11 @@ Copyright (C) Microsoft Corporation. 著作權所有,並保留一切權利。 that an explicit schema file was passed and existed when the command line parameters were checked but was deleted from disk before this check was made. LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + + MSBUILD : error MSB1059: Targets could not be printed. {0} + MSBUILD : error MSB1059: Targets could not be printed. {0} + {StrBegin="MSBUILD : error MSB1059: "} + MSBUILD : error MSB1002: This switch does not take any parameters. MSBUILD : error MSB1002: 這個參數不使用任何參數。 diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 667ef844a3c..eb2fd268eb6 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -555,6 +555,7 @@ string [] commandLine bool enableNodeReuse = false; #endif TextWriter preprocessWriter = null; + TextWriter targetsWriter = null; bool detailedSummary = false; ISet warningsAsErrors = null; ISet warningsAsMessages = null; @@ -588,6 +589,7 @@ string [] commandLine ref cpuCount, ref enableNodeReuse, ref preprocessWriter, + ref targetsWriter, ref detailedSummary, ref warningsAsErrors, ref warningsAsMessages, @@ -651,6 +653,7 @@ string [] commandLine cpuCount, enableNodeReuse, preprocessWriter, + targetsWriter, detailedSummary, warningsAsErrors, warningsAsMessages, @@ -959,6 +962,7 @@ internal static bool BuildProject int cpuCount, bool enableNodeReuse, TextWriter preprocessWriter, + TextWriter targetsWriter, bool detailedSummary, ISet warningsAsErrors, ISet warningsAsMessages, @@ -1056,6 +1060,7 @@ string outputResultsCache ToolsetDefinitionLocations toolsetDefinitionLocations = ToolsetDefinitionLocations.Default; bool preprocessOnly = preprocessWriter != null && !FileUtilities.IsSolutionFilename(projectFile); + bool targetsOnly = targetsWriter != null && !FileUtilities.IsSolutionFilename(projectFile); projectCollection = new ProjectCollection ( @@ -1102,7 +1107,13 @@ string outputResultsCache projectCollection.UnloadProject(project); success = true; } - else + + if (targetsOnly) + { + success = PrintTargets(projectFile, toolsVersion, globalProperties, targetsWriter, projectCollection); + } + + if (!preprocessOnly && !targetsOnly) { BuildParameters parameters = new BuildParameters(projectCollection); @@ -1292,6 +1303,28 @@ string outputResultsCache return success; } + private static bool PrintTargets(string projectFile, string toolsVersion, Dictionary globalProperties, TextWriter targetsWriter, ProjectCollection projectCollection) + { + try + { + Project project = projectCollection.LoadProject(projectFile, globalProperties, toolsVersion); + + foreach (string target in project.Targets.Keys) + { + targetsWriter.WriteLine(target); + } + + projectCollection.UnloadProject(project); + return true; + } + catch (Exception ex) + { + var message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TargetsCouldNotBePrinted", ex); + Console.Error.WriteLine(message); + return false; + } + } + private static (BuildResultCode result, Exception exception) ExecuteBuild(BuildManager buildManager, BuildRequestData request) { BuildSubmission submission; @@ -2011,6 +2044,7 @@ private static bool ProcessCommandLineSwitches ref int cpuCount, ref bool enableNodeReuse, ref TextWriter preprocessWriter, + ref TextWriter targetsWriter, ref bool detailedSummary, ref ISet warningsAsErrors, ref ISet warningsAsMessages, @@ -2126,6 +2160,7 @@ bool recursing ref cpuCount, ref enableNodeReuse, ref preprocessWriter, + ref targetsWriter, ref detailedSummary, ref warningsAsErrors, ref warningsAsMessages, @@ -2169,6 +2204,13 @@ bool recursing preprocessWriter = ProcessPreprocessSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Preprocess]); } + // determine what if any writer to print targets to + targetsWriter = null; + if (commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.Targets)) + { + targetsWriter = ProcessTargetsSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Targets]); + } + detailedSummary = commandLineSwitches.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.DetailedSummary); warningsAsErrors = ProcessWarnAsErrorSwitch(commandLineSwitches); @@ -2332,6 +2374,25 @@ internal static TextWriter ProcessPreprocessSwitch(string[] parameters) return writer; } + internal static TextWriter ProcessTargetsSwitch(string[] parameters) + { + TextWriter writer = Console.Out; + + if (parameters.Length > 0) + { + try + { + writer = FileUtilities.OpenWrite(parameters[parameters.Length - 1], append: false); + } + catch (Exception ex) when (ExceptionHandling.IsIoRelatedException(ex)) + { + CommandLineSwitchException.Throw("TargetsCouldNotBePrinted", parameters[parameters.Length - 1], ex.Message); + } + } + + return writer; + } + internal static ISet ProcessWarnAsErrorSwitch(CommandLineSwitches commandLineSwitches) { // TODO: Parse an environment variable as well? @@ -3663,6 +3724,7 @@ private static void ShowHelpMessage() Console.WriteLine(AssemblyResources.GetString("HelpMessage_24_NodeReuse")); #endif Console.WriteLine(AssemblyResources.GetString("HelpMessage_25_PreprocessSwitch")); + Console.WriteLine(AssemblyResources.GetString("HelpMessage_38_TargetsSwitch")); Console.WriteLine(AssemblyResources.GetString("HelpMessage_26_DetailedSummarySwitch")); Console.WriteLine(AssemblyResources.GetString("HelpMessage_31_RestoreSwitch"));