diff --git a/src/Tools/dotnet-format/CodeFormatter.cs b/src/Tools/dotnet-format/CodeFormatter.cs index 36247b6e2114f95c8102a384e3eef1fd73d14c4d..586e831c54c9f78a2335688e2d21f7cd4d1a97bc 100644 --- a/src/Tools/dotnet-format/CodeFormatter.cs +++ b/src/Tools/dotnet-format/CodeFormatter.cs @@ -21,12 +21,15 @@ namespace Microsoft.CodeAnalysis.Tools.CodeFormatter { internal static class CodeFormatter { - public static async Task FormatWorkspaceAsync(ILogger logger, string solutionOrProjectPath, bool isSolution, CancellationToken cancellationToken) + const int MaxLoggedWorkspaceWarnings = 5; + + public static async Task FormatWorkspaceAsync(ILogger logger, string solutionOrProjectPath, bool isSolution, bool logAllWorkspaceWarnings, CancellationToken cancellationToken) { logger.LogInformation(string.Format(Resources.Formatting_code_files_in_workspace_0, solutionOrProjectPath)); logger.LogTrace(Resources.Loading_workspace); + var loggedWarningCount = 0; var exitCode = 1; var workspaceStopwatch = Stopwatch.StartNew(); @@ -42,14 +45,7 @@ public static async Task FormatWorkspaceAsync(ILogger logger, string soluti using (var workspace = MSBuildWorkspace.Create(properties)) { - workspace.WorkspaceFailed += (s, e) => - { - if (e.Diagnostic.Kind != WorkspaceDiagnosticKind.Failure) - { - logger.LogError(e.Diagnostic.Message); - logger.LogError(Resources.Unable_to_load_workspace); - } - }; + workspace.WorkspaceFailed += LogWorkspaceWarnings; var projectPath = string.Empty; if (isSolution) @@ -73,6 +69,27 @@ public static async Task FormatWorkspaceAsync(ILogger logger, string soluti logger.LogInformation(Resources.Format_complete); return exitCode; + + void LogWorkspaceWarnings(object sender, WorkspaceDiagnosticEventArgs args) + { + if (args.Diagnostic.Kind == WorkspaceDiagnosticKind.Failure) + { + return; + } + + logger.LogWarning(args.Diagnostic.Message); + + if (!logAllWorkspaceWarnings) + { + loggedWarningCount++; + + if (loggedWarningCount == MaxLoggedWorkspaceWarnings) + { + logger.LogWarning(Resources.Maximum_number_of_workspace_warnings_to_log_has_been_reached_Set_the_verbosity_option_to_the_diagnostic_level_to_see_all_warnings); + ((MSBuildWorkspace)sender).WorkspaceFailed -= LogWorkspaceWarnings; + } + } + } } private static async Task FormatFilesInWorkspaceAsync(ILogger logger, Workspace workspace, string projectPath, ICodingConventionsManager codingConventionsManager, CancellationToken cancellationToken) diff --git a/src/Tools/dotnet-format/Program.cs b/src/Tools/dotnet-format/Program.cs index ffef8627b69cf2f4bcb8a1ef13778c85e5afb655..d4efcd21099edbfce261b35e8e589d162cc7d528 100644 --- a/src/Tools/dotnet-format/Program.cs +++ b/src/Tools/dotnet-format/Program.cs @@ -63,7 +63,8 @@ public static async Task Run(string workspace, string verbosity, IConsole c MSBuildEnvironment.ApplyEnvironmentVariables(workspaceDirectory); MSBuildCoreLoader.LoadDotnetInstance(workspaceDirectory); - return await CodeFormatter.FormatWorkspaceAsync(logger, workspacePath, isSolution, cancellationTokenSource.Token).ConfigureAwait(false); + return await CodeFormatter.FormatWorkspaceAsync( + logger, workspacePath, isSolution, logAllWorkspaceWarnings: logLevel == LogLevel.Trace, cancellationTokenSource.Token).ConfigureAwait(false); } catch (FileNotFoundException fex) { diff --git a/src/Tools/dotnet-format/README.md b/src/Tools/dotnet-format/README.md index b1a44a8949d562d9cb0a0b68842b51a51800213b..722cdf78d899b0c3da84f6763c62943cd1827d35 100644 --- a/src/Tools/dotnet-format/README.md +++ b/src/Tools/dotnet-format/README.md @@ -2,8 +2,20 @@ ============= `dotnet-format` is a code formatter for `dotnet` that applies style preferences to a project or solution. Preferences will be read from an `.editorconfig` file, if present, otherwise a default set of preferences will be used. +### How To Install + +The `dotnet-format` nuget package is currently being hosted on myget. You can visit the [dotnet-format myget page](https://dotnet.myget.org/feed/roslyn/package/nuget/dotnet-format) to get the latest version number. + +You can install the tool using the following command. + +```console +dotnet tool install -g dotnet-format --version --add-source https://dotnet.myget.org/F/roslyn/api/v3/index.json +``` + ### How To Use +By default `dotnet-format` will look in the current directory for a project or solution file and use that as the workspace to format. If more than one project or solution file is present in the current directory you will need to specify the workspace to format using the `-w` option. You can control how verbose the output will be by using the `-v` option. + ``` Usage: dotnet-format [options] @@ -21,11 +33,19 @@ Add `format` after `dotnet` and before the command arguments that you want to ru | Examples | | -------------------------------------------------------- | | dotnet **format** | -| dotnet **format** <workspace> | | dotnet **format** -w <workspace> | | dotnet **format** -v diag | +| dotnet **format** -w <workspace> -v diag | + +### How To Uninstall + +You can uninstall the tool using the following command. -## Build the Tool from source +```console +dotnet tool uninstall -g dotnet-format +``` + +### How To Build From Source You can build and package the tool using the following commands. The instructions assume that you are in the root of the repository. @@ -42,9 +62,3 @@ dotnet format ``` > Note: On macOS and Linux, `.\nupkg` will need be switched to `./nupkg` to accomodate for the different slash directions. - -You can uninstall the tool using the following command. - -```console -dotnet tool uninstall -g dotnet-format -``` diff --git a/src/Tools/dotnet-format/Resources.Designer.cs b/src/Tools/dotnet-format/Resources.Designer.cs index afa1e010047fb7f9fc33308b107e07229e7211d8..140954504637911b6beb671d73a6d7f1e4b37a08 100644 --- a/src/Tools/dotnet-format/Resources.Designer.cs +++ b/src/Tools/dotnet-format/Resources.Designer.cs @@ -153,6 +153,16 @@ internal class Resources { } } + /// + /// Looks up a localized string similar to Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings.. + /// + internal static string Maximum_number_of_workspace_warnings_to_log_has_been_reached_Set_the_verbosity_option_to_the_diagnostic_level_to_see_all_warnings { + get { + return ResourceManager.GetString("Maximum_number_of_workspace_warnings_to_log_has_been_reached_Set_the_verbosity_op" + + "tion_to_the_diagnostic_level_to_see_all_warnings", resourceCulture); + } + } + /// /// Looks up a localized string similar to Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option.. /// diff --git a/src/Tools/dotnet-format/Resources.resx b/src/Tools/dotnet-format/Resources.resx index c3d6ef52f4bc3414eb0539f1cf40b8c32333baae..b57b654c48bf23f5b404ebd1aeefed8f75905a1a 100644 --- a/src/Tools/dotnet-format/Resources.resx +++ b/src/Tools/dotnet-format/Resources.resx @@ -177,4 +177,7 @@ The solution or project file to operate on. If a file is not specified, the command will search the current directory for one. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + \ No newline at end of file diff --git a/src/Tools/dotnet-format/xlf/Resources.cs.xlf b/src/Tools/dotnet-format/xlf/Resources.cs.xlf index 623a0ff8cb09548d1aed7938ee6d4b8ff76912d7..b3ba5dbf1457aa69c2a01f47daa3dbc3ff1724e1 100644 --- a/src/Tools/dotnet-format/xlf/Resources.cs.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.cs.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.de.xlf b/src/Tools/dotnet-format/xlf/Resources.de.xlf index 897893b28367a4b4f1c84402622a75a9af1e9c4a..2071a5cafd117c526759baba29b2669f55f80ec9 100644 --- a/src/Tools/dotnet-format/xlf/Resources.de.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.de.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.es.xlf b/src/Tools/dotnet-format/xlf/Resources.es.xlf index 626b6ba4805d50ba9b470f754342dc519b7e9b4f..aaf481fa3ee0c6990871dbb046a4f7d1d1e299eb 100644 --- a/src/Tools/dotnet-format/xlf/Resources.es.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.es.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.fr.xlf b/src/Tools/dotnet-format/xlf/Resources.fr.xlf index 2e345eb28cdc1f5b2eb5d1258d3a56025eaa0bd3..b5d3f491698fbcedc117d5a27143aae835b040ac 100644 --- a/src/Tools/dotnet-format/xlf/Resources.fr.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.fr.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.it.xlf b/src/Tools/dotnet-format/xlf/Resources.it.xlf index dd0710dc88b7f7b380d81a1c92d5d37d33715f03..468828957cc10fc593ffdeb2bb68344b8efbb790 100644 --- a/src/Tools/dotnet-format/xlf/Resources.it.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.it.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.ja.xlf b/src/Tools/dotnet-format/xlf/Resources.ja.xlf index bdcd0c26c3a8adf2b25cbbcad0810472b088a177..44e1b8adbbc1f214055cea6f37ad47a64b8ba0e2 100644 --- a/src/Tools/dotnet-format/xlf/Resources.ja.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.ja.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.ko.xlf b/src/Tools/dotnet-format/xlf/Resources.ko.xlf index 26c894c4c63f62a722e0b26be2ceb5b3d3a8f7e0..79b5a40d9adf53172da94d7c2eb2dbaf8792f914 100644 --- a/src/Tools/dotnet-format/xlf/Resources.ko.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.ko.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.pl.xlf b/src/Tools/dotnet-format/xlf/Resources.pl.xlf index 0161313d3ec8031e77baf9652e201cc0e2789bb1..37323e0c19fa28e35e5e8f2e7ca0892779a9063b 100644 --- a/src/Tools/dotnet-format/xlf/Resources.pl.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.pl.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.pt-BR.xlf b/src/Tools/dotnet-format/xlf/Resources.pt-BR.xlf index def87b371b24f508bb1bd5000a3f90e91ac026fb..f2510400e55d591213fba10ac0979240ae5eb7b8 100644 --- a/src/Tools/dotnet-format/xlf/Resources.pt-BR.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.pt-BR.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.ru.xlf b/src/Tools/dotnet-format/xlf/Resources.ru.xlf index d2071bd9fe5069e251f8a332d006b86207065a30..3dd34e9fd14d3c754f3adf149f48834ca7daab32 100644 --- a/src/Tools/dotnet-format/xlf/Resources.ru.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.ru.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.tr.xlf b/src/Tools/dotnet-format/xlf/Resources.tr.xlf index 952623dbbb8e0665b43973aeef98a8f7411cbcc4..397d381789ab3036486d31d1a743d4bd37a73ff9 100644 --- a/src/Tools/dotnet-format/xlf/Resources.tr.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.tr.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.zh-Hans.xlf b/src/Tools/dotnet-format/xlf/Resources.zh-Hans.xlf index 0f65f4499b478c0e7786ab307b297712e94ac800..c111f9eda7cbfb53843e765be8e20c172bcb5cda 100644 --- a/src/Tools/dotnet-format/xlf/Resources.zh-Hans.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.zh-Hans.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. diff --git a/src/Tools/dotnet-format/xlf/Resources.zh-Hant.xlf b/src/Tools/dotnet-format/xlf/Resources.zh-Hant.xlf index 884cf53f49f727180851adab0c70e3c18ca66dcc..15dd3185028041df3870ef6cc513edc044a72293 100644 --- a/src/Tools/dotnet-format/xlf/Resources.zh-Hant.xlf +++ b/src/Tools/dotnet-format/xlf/Resources.zh-Hant.xlf @@ -52,6 +52,11 @@ Loading workspace. + + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + Maximum number of workspace warnings to log has been reached. Set the --verbosity option to the 'diagnostic' level to see all warnings. + + Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option. Multiple MSBuild project files found in '{0}'. Specify which to use with the --workspace option.