Exemplo n.º 1
0
        private async Task <List <FormattedFile> > TestFormattedFiles(string testCode)
        {
            var text = SourceText.From(testCode, Encoding.UTF8);

            TestState.Sources.Add(text);

            var solution      = GetSolution(TestState.Sources.ToArray(), TestState.AdditionalFiles.ToArray(), TestState.AdditionalReferences.ToArray());
            var project       = solution.Projects.Single();
            var document      = project.Documents.Single();
            var fileMatcher   = SourceFileMatcher.CreateMatcher(new[] { document.FilePath }, exclude: Array.Empty <string>());
            var formatOptions = new FormatOptions(
                workspaceFilePath: project.FilePath,
                workspaceType: WorkspaceType.Folder,
                logLevel: LogLevel.Trace,
                saveFormattedFiles: false,
                changesAreErrors: false,
                fileMatcher,
                reportPath: string.Empty,
                includeGeneratedFiles: false);

            var pathsToFormat = await GetOnlyFileToFormatAsync(solution, EditorConfig);

            var formattedFiles = new List <FormattedFile>();
            await Formatter.FormatAsync(solution, pathsToFormat, formatOptions, new TestLogger(), formattedFiles, default);

            return(formattedFiles);
        }
Exemplo n.º 2
0
 public FormatOptions(
     string workspaceFilePath,
     WorkspaceType workspaceType,
     LogLevel logLevel,
     FixCategory fixCategory,
     DiagnosticSeverity codeStyleSeverity,
     DiagnosticSeverity analyzerSeverity,
     bool saveFormattedFiles,
     bool changesAreErrors,
     SourceFileMatcher fileMatcher,
     string?reportPath,
     bool includeGeneratedFiles)
 {
     WorkspaceFilePath     = workspaceFilePath;
     WorkspaceType         = workspaceType;
     LogLevel              = logLevel;
     FixCategory           = fixCategory;
     CodeStyleSeverity     = codeStyleSeverity;
     AnalyzerSeverity      = analyzerSeverity;
     SaveFormattedFiles    = saveFormattedFiles;
     ChangesAreErrors      = changesAreErrors;
     FileMatcher           = fileMatcher;
     ReportPath            = reportPath;
     IncludeGeneratedFiles = includeGeneratedFiles;
 }
Exemplo n.º 3
0
 public void Deconstruct(
     out string workspaceFilePath,
     out WorkspaceType workspaceType,
     out LogLevel logLevel,
     out FixCategory fixCategory,
     out DiagnosticSeverity codeStyleSeverity,
     out DiagnosticSeverity analyzerSeverity,
     out bool saveFormattedFiles,
     out bool changesAreErrors,
     out SourceFileMatcher fileMatcher,
     out string?reportPath,
     out bool includeGeneratedFiles)
 {
     workspaceFilePath     = WorkspaceFilePath;
     workspaceType         = WorkspaceType;
     logLevel              = LogLevel;
     fixCategory           = FixCategory;
     codeStyleSeverity     = CodeStyleSeverity;
     analyzerSeverity      = AnalyzerSeverity;
     saveFormattedFiles    = SaveFormattedFiles;
     changesAreErrors      = ChangesAreErrors;
     fileMatcher           = FileMatcher;
     reportPath            = ReportPath;
     includeGeneratedFiles = IncludeGeneratedFiles;
 }
Exemplo n.º 4
0
        private static Workspace OpenFolderWorkspace(string workspacePath, SourceFileMatcher fileMatcher)
        {
            var folderWorkspace = FolderWorkspace.Create();

            folderWorkspace.OpenFolder(workspacePath, fileMatcher);
            return(folderWorkspace);
        }
Exemplo n.º 5
0
        private async Task <List <FormattedFile> > TestFormattedFiles(string testCode)
        {
            var text = SourceText.From(testCode, Encoding.UTF8);

            TestState.Sources.Add(text);

            var solution = await GetSolutionAsync(TestState.Sources.ToArray(), TestState.AdditionalFiles.ToArray(), TestState.AdditionalReferences.ToArray(), EditorConfig);

            var project  = solution.Projects.Single();
            var document = project.Documents.Single();

            var fileMatcher   = SourceFileMatcher.CreateMatcher(new[] { document.FilePath }, exclude: Array.Empty <string>());
            var formatOptions = new FormatOptions(
                WorkspaceFilePath: project.FilePath,
                WorkspaceType: WorkspaceType.Folder,
                NoRestore: false,
                LogLevel: LogLevel.Trace,
                FixCategory: FixCategory.Whitespace,
                CodeStyleSeverity: DiagnosticSeverity.Error,
                AnalyzerSeverity: DiagnosticSeverity.Error,
                Diagnostics: ImmutableHashSet <string> .Empty,
                SaveFormattedFiles: false,
                ChangesAreErrors: false,
                fileMatcher,
                ReportPath: string.Empty,
                IncludeGeneratedFiles: false,
                BinaryLogPath: null);

            var pathsToFormat = GetOnlyFileToFormat(solution);

            var formattedFiles = new List <FormattedFile>();
            await Formatter.FormatAsync(solution, pathsToFormat, formatOptions, new TestLogger(), formattedFiles, default);

            return(formattedFiles);
        }
            public static SolutionInfo LoadSolutionInfo(string folderPath, SourceFileMatcher fileMatcher)
            {
                var absoluteFolderPath = Path.GetFullPath(folderPath, Directory.GetCurrentDirectory());

                var filePaths         = GetMatchingFilePaths(absoluteFolderPath, fileMatcher);
                var editorConfigPaths = EditorConfigFinder.GetEditorConfigPaths(folderPath);

                var projectInfos = ImmutableArray.CreateBuilder <ProjectInfo>(ProjectLoaders.Length);

                // Create projects for each of the supported languages.
                foreach (var loader in ProjectLoaders)
                {
                    var projectInfo = loader.LoadProjectInfo(folderPath, filePaths, editorConfigPaths);
                    if (projectInfo is null)
                    {
                        continue;
                    }

                    projectInfos.Add(projectInfo);
                }

                // Construct workspace from loaded project infos.
                return(SolutionInfo.Create(
                           SolutionId.CreateNewId(debugName: absoluteFolderPath),
                           version: default,
Exemplo n.º 7
0
        private protected async Task <SourceText> TestAsync(string testCode, string expectedCode, string editorConfig, Encoding encoding)
        {
            var text = SourceText.From(testCode, encoding);

            TestState.Sources.Add(text);

            var solution = GetSolution(TestState.Sources.ToArray(), TestState.AdditionalFiles.ToArray(), TestState.AdditionalReferences.ToArray(), editorConfig);
            var project  = solution.Projects.Single();
            var document = project.Documents.Single();

            var fileMatcher   = SourceFileMatcher.CreateMatcher(new[] { document.FilePath }, exclude: Array.Empty <string>());
            var formatOptions = new FormatOptions(
                workspaceFilePath: project.FilePath,
                workspaceType: WorkspaceType.Folder,
                logLevel: LogLevel.Trace,
                saveFormattedFiles: false,
                changesAreErrors: false,
                fileMatcher,
                reportPath: string.Empty,
                includeGeneratedFiles: false);

            var pathsToFormat = GetOnlyFileToFormat(solution);

            var formattedSolution = await Formatter.FormatAsync(solution, pathsToFormat, formatOptions, Logger, new List <FormattedFile>(), default);

            var formattedDocument = GetOnlyDocument(formattedSolution);
            var formattedText     = await formattedDocument.GetTextAsync();

            Assert.Equal(expectedCode, formattedText.ToString());

            return(formattedText);
        }
Exemplo n.º 8
0
        public async Task <string> TestFormatWorkspaceAsync(string workspaceFilePath, IEnumerable <string> include, IEnumerable <string> exclude, int expectedExitCode, int expectedFilesFormatted, int expectedFileCount)
        {
            var workspacePath = Path.GetFullPath(workspaceFilePath);

            WorkspaceType workspaceType;

            if (Directory.Exists(workspacePath))
            {
                workspaceType = WorkspaceType.Folder;
            }
            else
            {
                workspaceType = workspacePath.EndsWith(".sln")
                    ? WorkspaceType.Solution
                    : WorkspaceType.Project;
            }

            var fileMatcher   = SourceFileMatcher.CreateMatcher(include, exclude);
            var logger        = new TestLogger();
            var formatOptions = new FormatOptions(
                workspacePath,
                workspaceType,
                LogLevel.Trace,
                saveFormattedFiles: false,
                changesAreErrors: false,
                fileMatcher,
                reportPath: string.Empty);
            var formatResult = await CodeFormatter.FormatWorkspaceAsync(formatOptions, logger, CancellationToken.None);

            Assert.Equal(expectedExitCode, formatResult.ExitCode);
            Assert.Equal(expectedFilesFormatted, formatResult.FilesFormatted);
            Assert.Equal(expectedFileCount, formatResult.FileCount);

            return(logger.GetLog());
        }
Exemplo n.º 9
0
        internal async Task <string> TestFormatWorkspaceAsync(
            string workspaceFilePath,
            string[] include,
            string[] exclude,
            bool includeGenerated,
            int expectedExitCode,
            int expectedFilesFormatted,
            int expectedFileCount,
            FixCategory fixCategory = FixCategory.Whitespace,
            DiagnosticSeverity codeStyleSeverity = DiagnosticSeverity.Error,
            DiagnosticSeverity analyzerSeverity  = DiagnosticSeverity.Error)
        {
            var workspacePath = Path.GetFullPath(workspaceFilePath);

            WorkspaceType workspaceType;

            if (Directory.Exists(workspacePath))
            {
                workspaceType = WorkspaceType.Folder;
            }
            else
            {
                workspaceType = workspacePath.EndsWith(".sln")
                    ? WorkspaceType.Solution
                    : WorkspaceType.Project;
            }

            var logger      = new TestLogger();
            var msBuildPath = MSBuildRegistrar.RegisterInstance(logger);

            logger.LogDebug(Resources.The_dotnet_runtime_version_is_0, Program.GetRuntimeVersion());
            logger.LogTrace(Resources.Using_msbuildexe_located_in_0, msBuildPath);

            var fileMatcher   = SourceFileMatcher.CreateMatcher(include, exclude);
            var formatOptions = new FormatOptions(
                workspacePath,
                workspaceType,
                LogLevel.Trace,
                fixCategory,
                codeStyleSeverity,
                analyzerSeverity,
                saveFormattedFiles: false,
                changesAreErrors: false,
                fileMatcher,
                reportPath: string.Empty,
                includeGenerated);
            var formatResult = await CodeFormatter.FormatWorkspaceAsync(formatOptions, logger, CancellationToken.None);

            var log = logger.GetLog();

            _output.WriteLine(log);

            Assert.Equal(expectedExitCode, formatResult.ExitCode);
            Assert.Equal(expectedFilesFormatted, formatResult.FilesFormatted);
            Assert.Equal(expectedFileCount, formatResult.FileCount);

            return(log);
        }
Exemplo n.º 10
0
        public Solution OpenFolder(string folderPath, SourceFileMatcher fileMatcher)
        {
            if (string.IsNullOrEmpty(folderPath) || !Directory.Exists(folderPath))
            {
                throw new ArgumentException($"Folder '{folderPath}' does not exist.", nameof(folderPath));
            }

            ClearSolution();

            var solutionInfo = FolderSolutionLoader.LoadSolutionInfo(folderPath, fileMatcher);

            OnSolutionAdded(solutionInfo);

            return(CurrentSolution);
        }
Exemplo n.º 11
0
        public static async Task <int> Run(
            string?workspace,
            bool noRestore,
            bool folder,
            bool fixWhitespace,
            string?fixStyle,
            string?fixAnalyzers,
            string[] diagnostics,
            string?verbosity,
            bool check,
            string[] include,
            string[] exclude,
            string?report,
            bool includeGenerated,
            string?binarylog,
            IConsole console = null !)
        {
            if (s_parseResult == null)
            {
                return(1);
            }

            // Setup logging.
            var logLevel = GetLogLevel(verbosity);
            var logger   = SetupLogging(console, minimalLogLevel: logLevel, minimalErrorLevel: LogLevel.Warning);

            // Hook so we can cancel and exit when ctrl+c is pressed.
            var cancellationTokenSource = new CancellationTokenSource();

            Console.CancelKeyPress += (sender, e) =>
            {
                e.Cancel = true;
                cancellationTokenSource.Cancel();
            };

            var currentDirectory = string.Empty;

            try
            {
                currentDirectory = Environment.CurrentDirectory;

                var formatVersion = GetVersion();
                logger.LogDebug(Resources.The_dotnet_format_version_is_0, formatVersion);

                string?       workspaceDirectory;
                string        workspacePath;
                WorkspaceType workspaceType;

                // The folder option means we should treat the project path as a folder path.
                if (folder)
                {
                    // If folder isn't populated, then use the current directory
                    workspacePath      = Path.GetFullPath(workspace ?? ".", Environment.CurrentDirectory);
                    workspaceDirectory = workspacePath;
                    workspaceType      = WorkspaceType.Folder;
                }
                else
                {
                    var(isSolution, workspaceFilePath) = MSBuildWorkspaceFinder.FindWorkspace(currentDirectory, workspace);

                    workspacePath = workspaceFilePath;
                    workspaceType = isSolution
                        ? WorkspaceType.Solution
                        : WorkspaceType.Project;

                    // To ensure we get the version of MSBuild packaged with the dotnet SDK used by the
                    // workspace, use its directory as our working directory which will take into account
                    // a global.json if present.
                    workspaceDirectory = Path.GetDirectoryName(workspacePath);
                    if (workspaceDirectory is null)
                    {
                        throw new Exception($"Unable to find folder at '{workspacePath}'");
                    }
                }

                if (workspaceType != WorkspaceType.Folder)
                {
                    var runtimeVersion = GetRuntimeVersion();
                    logger.LogDebug(Resources.The_dotnet_runtime_version_is_0, runtimeVersion);

                    // Load MSBuild
                    Environment.CurrentDirectory = workspaceDirectory;

                    if (!TryGetDotNetCliVersion(out var dotnetVersion))
                    {
                        logger.LogError(Resources.Unable_to_locate_dotnet_CLI_Ensure_that_it_is_on_the_PATH);
                        return(UnableToLocateDotNetCliExitCode);
                    }

                    logger.LogTrace(Resources.The_dotnet_CLI_version_is_0, dotnetVersion);

                    if (!TryLoadMSBuild(out var msBuildPath))
                    {
                        logger.LogError(Resources.Unable_to_locate_MSBuild_Ensure_the_NET_SDK_was_installed_with_the_official_installer);
                        return(UnableToLocateMSBuildExitCode);
                    }

                    logger.LogTrace(Resources.Using_msbuildexe_located_in_0, msBuildPath);
                }

                var fixType = FixCategory.None;
                if (s_parseResult.WasOptionUsed("--fix-style", "-s"))
                {
                    fixType |= FixCategory.CodeStyle;
                }

                if (s_parseResult.WasOptionUsed("--fix-analyzers", "-a"))
                {
                    fixType |= FixCategory.Analyzers;
                }

                if (fixType == FixCategory.None && diagnostics.Length > 0)
                {
                    logger.LogWarning(Resources.The_diagnostics_option_only_applies_when_fixing_style_or_running_analyzers);
                }

                if (fixType == FixCategory.None || fixWhitespace)
                {
                    fixType |= FixCategory.Whitespace;
                }

                HandleStandardInput(logger, ref include, ref exclude);

                var fileMatcher = SourceFileMatcher.CreateMatcher(include, exclude);

                var formatOptions = new FormatOptions(
                    workspacePath,
                    workspaceType,
                    noRestore,
                    logLevel,
                    fixType,
                    codeStyleSeverity: GetSeverity(fixStyle ?? FixSeverity.Error),
                    analyzerSeverity: GetSeverity(fixAnalyzers ?? FixSeverity.Error),
                    diagnostics: diagnostics.ToImmutableHashSet(),
                    saveFormattedFiles: !check,
                    changesAreErrors: check,
                    fileMatcher,
                    reportPath: report,
                    includeGenerated);

                var formatResult = await CodeFormatter.FormatWorkspaceAsync(
                    formatOptions,
                    logger,
                    cancellationTokenSource.Token,
                    binaryLogPath : GetBinaryLogPath(s_parseResult, binarylog)).ConfigureAwait(false);

                return(GetExitCode(formatResult, check));
Exemplo n.º 12
0
        public static async Task <int> Run(string folder, string workspace, string verbosity, bool check, string[] include, string[] exclude, string report, IConsole console = null)
        {
            // Setup logging.
            var serviceCollection = new ServiceCollection();
            var logLevel          = GetLogLevel(verbosity);

            ConfigureServices(serviceCollection, console, logLevel);

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var logger          = serviceProvider.GetService <ILogger <Program> >();

            // Hook so we can cancel and exit when ctrl+c is pressed.
            var cancellationTokenSource = new CancellationTokenSource();

            Console.CancelKeyPress += (sender, e) =>
            {
                e.Cancel = true;
                cancellationTokenSource.Cancel();
            };

            var currentDirectory = string.Empty;

            try
            {
                currentDirectory = Environment.CurrentDirectory;

                string        workspaceDirectory;
                string        workspacePath;
                WorkspaceType workspaceType;

                if (!string.IsNullOrEmpty(folder) && !string.IsNullOrEmpty(workspace))
                {
                    logger.LogWarning(Resources.Cannot_specify_both_folder_and_workspace_options);
                    return(1);
                }

                if (!string.IsNullOrEmpty(folder))
                {
                    folder             = Path.GetFullPath(folder, Environment.CurrentDirectory);
                    workspacePath      = folder;
                    workspaceDirectory = workspacePath;
                    workspaceType      = WorkspaceType.Folder;
                }
                else
                {
                    var(isSolution, workspaceFilePath) = MSBuildWorkspaceFinder.FindWorkspace(currentDirectory, workspace);

                    workspacePath = workspaceFilePath;
                    workspaceType = isSolution
                        ? WorkspaceType.Solution
                        : WorkspaceType.Project;

                    // To ensure we get the version of MSBuild packaged with the dotnet SDK used by the
                    // workspace, use its directory as our working directory which will take into account
                    // a global.json if present.
                    workspaceDirectory = Path.GetDirectoryName(workspacePath);
                }

                Environment.CurrentDirectory = workspaceDirectory;

                // Since we are running as a dotnet tool we should be able to find an instance of
                // MSBuild in a .NET Core SDK.
                var msBuildInstance = Build.Locator.MSBuildLocator.QueryVisualStudioInstances().First();

                // Since we do not inherit msbuild.deps.json when referencing the SDK copy
                // of MSBuild and because the SDK no longer ships with version matched assemblies, we
                // register an assembly loader that will load assemblies from the msbuild path with
                // equal or higher version numbers than requested.
                LooseVersionAssemblyLoader.Register(msBuildInstance.MSBuildPath);

                Build.Locator.MSBuildLocator.RegisterInstance(msBuildInstance);

                var fileMatcher = SourceFileMatcher.CreateMatcher(include, exclude);

                var formatOptions = new FormatOptions(
                    workspacePath,
                    workspaceType,
                    logLevel,
                    saveFormattedFiles: !check,
                    changesAreErrors: check,
                    fileMatcher,
                    reportPath: report);

                var formatResult = await CodeFormatter.FormatWorkspaceAsync(
                    formatOptions,
                    logger,
                    cancellationTokenSource.Token).ConfigureAwait(false);

                return(GetExitCode(formatResult, check));
            }
            catch (FileNotFoundException fex)
            {
                logger.LogError(fex.Message);
                return(UnhandledExceptionExitCode);
            }
            catch (OperationCanceledException)
            {
                return(UnhandledExceptionExitCode);
            }
            finally
            {
                if (!string.IsNullOrEmpty(currentDirectory))
                {
                    Environment.CurrentDirectory = currentDirectory;
                }
            }
        }
Exemplo n.º 13
0
        internal async Task <string> TestFormatWorkspaceAsync(
            string workspaceFilePath,
            string[] include,
            string[] exclude,
            bool includeGenerated,
            int expectedExitCode,
            int expectedFilesFormatted,
            int expectedFileCount,
            FixCategory fixCategory = FixCategory.Whitespace,
            DiagnosticSeverity codeStyleSeverity = DiagnosticSeverity.Error,
            DiagnosticSeverity analyzerSeverity  = DiagnosticSeverity.Error,
            string[] diagnostics    = null,
            bool noRestore          = false,
            bool saveFormattedFiles = false)
        {
            var currentDirectory = Environment.CurrentDirectory;

            Environment.CurrentDirectory = TestProjectsPathHelper.GetProjectsDirectory();

            var workspacePath = Path.GetFullPath(workspaceFilePath);

            WorkspaceType workspaceType;

            if (Directory.Exists(workspacePath))
            {
                workspaceType = WorkspaceType.Folder;
            }
            else
            {
                workspaceType = workspacePath.EndsWith("proj")
                    ? WorkspaceType.Project
                    : WorkspaceType.Solution;
            }

            var logger      = new TestLogger();
            var msBuildPath = MSBuildRegistrar.RegisterInstance();

            logger.LogTrace(Resources.Using_msbuildexe_located_in_0, msBuildPath);

            var fileMatcher   = SourceFileMatcher.CreateMatcher(include, exclude);
            var formatOptions = new FormatOptions(
                workspacePath,
                workspaceType,
                noRestore,
                LogLevel.Trace,
                fixCategory,
                codeStyleSeverity,
                analyzerSeverity,
                diagnostics?.ToImmutableHashSet() ?? ImmutableHashSet <string> .Empty,
                ExcludeDiagnostics: ImmutableHashSet <string> .Empty,
                saveFormattedFiles,
                ChangesAreErrors: false,
                fileMatcher,
                ReportPath: string.Empty,
                IncludeGeneratedFiles: includeGenerated,
                BinaryLogPath: null);
            var formatResult = await CodeFormatter.FormatWorkspaceAsync(formatOptions, logger, CancellationToken.None);

            Environment.CurrentDirectory = currentDirectory;

            var log = logger.GetLog();

            try
            {
                Assert.Equal(expectedExitCode, formatResult.ExitCode);
                Assert.Equal(expectedFilesFormatted, formatResult.FilesFormatted);
                Assert.Equal(expectedFileCount, formatResult.FileCount);
            }
            catch
            {
                _output.WriteLine(log);
                throw;
            }

            return(log);
        }
Exemplo n.º 14
0
        public static async Task <int> Run(
            string?workspace,
            bool folder,
            string?fixStyle,
            string?fixAnalyzers,
            string?verbosity,
            bool check,
            string[] include,
            string[] exclude,
            string?report,
            bool includeGenerated,
            IConsole console = null !)
        {
            if (s_parseResult == null)
            {
                return(1);
            }

            // Setup logging.
            var logLevel = GetLogLevel(verbosity);
            var logger   = SetupLogging(console, logLevel);

            // Hook so we can cancel and exit when ctrl+c is pressed.
            var cancellationTokenSource = new CancellationTokenSource();

            Console.CancelKeyPress += (sender, e) =>
            {
                e.Cancel = true;
                cancellationTokenSource.Cancel();
            };

            var currentDirectory = string.Empty;

            try
            {
                currentDirectory = Environment.CurrentDirectory;


                string        workspaceDirectory;
                string        workspacePath;
                WorkspaceType workspaceType;

                // The folder option means we should treat the project path as a folder path.
                if (folder)
                {
                    // If folder isn't populated, then use the current directory
                    workspacePath      = Path.GetFullPath(workspace ?? ".", Environment.CurrentDirectory);
                    workspaceDirectory = workspacePath;
                    workspaceType      = WorkspaceType.Folder;
                }
                else
                {
                    var(isSolution, workspaceFilePath) = MSBuildWorkspaceFinder.FindWorkspace(currentDirectory, workspace);

                    workspacePath = workspaceFilePath;
                    workspaceType = isSolution
                        ? WorkspaceType.Solution
                        : WorkspaceType.Project;

                    // To ensure we get the version of MSBuild packaged with the dotnet SDK used by the
                    // workspace, use its directory as our working directory which will take into account
                    // a global.json if present.
                    workspaceDirectory = Path.GetDirectoryName(workspacePath);
                    if (workspaceDirectory is null)
                    {
                        throw new Exception($"Unable to find folder at '{workspacePath}'");
                    }
                }

                // Load MSBuild
                Environment.CurrentDirectory = workspaceDirectory;

                if (!TryGetDotNetCliVersion(out var dotnetVersion))
                {
                    logger.LogError(Resources.Unable_to_locate_dotnet_CLI_Ensure_that_it_is_on_the_PATH);
                    return(UnableToLocateDotNetCliExitCode);
                }

                logger.LogTrace(Resources.The_dotnet_CLI_version_is_0, dotnetVersion);

                if (!TryLoadMSBuild(out var msBuildPath))
                {
                    logger.LogError(Resources.Unable_to_locate_MSBuild_Ensure_the_NET_SDK_was_installed_with_the_official_installer);
                    return(UnableToLocateMSBuildExitCode);
                }

                logger.LogTrace(Resources.Using_msbuildexe_located_in_0, msBuildPath);

                var fileMatcher = SourceFileMatcher.CreateMatcher(include, exclude);

                var formatOptions = new FormatOptions(
                    workspacePath,
                    workspaceType,
                    logLevel,
                    fixCodeStyle: s_parseResult.WasOptionUsed("--fix-style", "-fs"),
                    codeStyleSeverity: GetSeverity(fixStyle ?? FixSeverity.Error),
                    fixAnalyzers: s_parseResult.WasOptionUsed("--fix-analyzers", "-fa"),
                    analyerSeverity: GetSeverity(fixAnalyzers ?? FixSeverity.Error),
                    saveFormattedFiles: !check,
                    changesAreErrors: check,
                    fileMatcher,
                    reportPath: report,
                    includeGenerated);

                var formatResult = await CodeFormatter.FormatWorkspaceAsync(
                    formatOptions,
                    logger,
                    cancellationTokenSource.Token,
                    createBinaryLog : logLevel == LogLevel.Trace).ConfigureAwait(false);

                return(GetExitCode(formatResult, check));
            }
            catch (FileNotFoundException fex)
            {
                logger.LogError(fex.Message);
                return(UnhandledExceptionExitCode);
            }
            catch (OperationCanceledException)
            {
                return(UnhandledExceptionExitCode);
            }
            finally
            {
                if (!string.IsNullOrEmpty(currentDirectory))
                {
                    Environment.CurrentDirectory = currentDirectory;
                }
            }
        }