diff --git a/src/BuiltInTools/dotnet-format/CodeFormatter.cs b/src/BuiltInTools/dotnet-format/CodeFormatter.cs index e96f713593a1..bd0382c5c885 100644 --- a/src/BuiltInTools/dotnet-format/CodeFormatter.cs +++ b/src/BuiltInTools/dotnet-format/CodeFormatter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Immutable; @@ -25,8 +25,7 @@ internal static class CodeFormatter public static async Task FormatWorkspaceAsync( FormatOptions formatOptions, ILogger logger, - CancellationToken cancellationToken, - string? binaryLogPath = null) + CancellationToken cancellationToken) { var logWorkspaceWarnings = formatOptions.LogLevel == LogLevel.Trace; @@ -38,7 +37,7 @@ public static async Task FormatWorkspaceAsync( using var workspace = formatOptions.WorkspaceType == WorkspaceType.Folder ? OpenFolderWorkspace(formatOptions.WorkspaceFilePath, formatOptions.FileMatcher) - : await OpenMSBuildWorkspaceAsync(formatOptions.WorkspaceFilePath, formatOptions.WorkspaceType, formatOptions.NoRestore, formatOptions.FixCategory != FixCategory.Whitespace, binaryLogPath, logWorkspaceWarnings, logger, cancellationToken).ConfigureAwait(false); + : await OpenMSBuildWorkspaceAsync(formatOptions.WorkspaceFilePath, formatOptions.WorkspaceType, formatOptions.NoRestore, formatOptions.FixCategory != FixCategory.Whitespace, formatOptions.BinaryLogPath, logWorkspaceWarnings, logger, formatOptions.TargetFramework, cancellationToken).ConfigureAwait(false); if (workspace is null) { @@ -126,6 +125,7 @@ private static Workspace OpenFolderWorkspace(string workspacePath, SourceFileMat string? binaryLogPath, bool logWorkspaceWarnings, ILogger logger, + string? targetFramework, CancellationToken cancellationToken) { if (requiresSemantics && @@ -135,7 +135,7 @@ await DotNetHelper.PerformRestoreAsync(solutionOrProjectPath, logger) != 0) throw new Exception("Restore operation failed."); } - return await MSBuildWorkspaceLoader.LoadAsync(solutionOrProjectPath, workspaceType, binaryLogPath, logWorkspaceWarnings, logger, cancellationToken); + return await MSBuildWorkspaceLoader.LoadAsync(solutionOrProjectPath, workspaceType, binaryLogPath, logWorkspaceWarnings, logger, targetFramework, cancellationToken); } private static async Task RunCodeFormattersAsync( diff --git a/src/BuiltInTools/dotnet-format/Commands/FormatCommandCommon.cs b/src/BuiltInTools/dotnet-format/Commands/FormatCommandCommon.cs index 269da41d2d41..603e1f3e9eec 100644 --- a/src/BuiltInTools/dotnet-format/Commands/FormatCommandCommon.cs +++ b/src/BuiltInTools/dotnet-format/Commands/FormatCommandCommon.cs @@ -34,6 +34,11 @@ internal static class FormatCommandCommon { Description = Resources.Doesnt_execute_an_implicit_restore_before_formatting, }; + internal static readonly Option FrameworkOption = new Option("--framework", "-f") + { + HelpName = "framework", + Description = Resources.The_target_framework_to_use_when_loading_the_workspace, + }; internal static readonly Option VerifyNoChanges = new("--verify-no-changes") { Description = Resources.Verify_no_formatting_changes_would_be_performed_Terminates_with_a_non_zero_exit_code_if_any_files_would_have_been_formatted, @@ -106,8 +111,7 @@ internal static async Task FormatAsync(FormatOptions formatOptions, ILogger var formatResult = await CodeFormatter.FormatWorkspaceAsync( formatOptions, logger, - cancellationToken, - binaryLogPath: formatOptions.BinaryLogPath).ConfigureAwait(false); + cancellationToken).ConfigureAwait(false); return formatResult.GetExitCode(formatOptions.ChangesAreErrors); } @@ -115,6 +119,7 @@ public static void AddCommonOptions(this Command command) { command.Arguments.Add(SlnOrProjectArgument); command.Options.Add(NoRestoreOption); + command.Options.Add(FrameworkOption); command.Options.Add(VerifyNoChanges); command.Options.Add(IncludeOption); command.Options.Add(ExcludeOption); @@ -211,6 +216,12 @@ public static FormatOptions ParseCommonOptions(this ParseResult parseResult, For } } + if (parseResult.GetResult(FrameworkOption) is not null && + parseResult.GetValue(FrameworkOption) is string { Length: > 0 } framework) + { + formatOptions = formatOptions with { TargetFramework = framework }; + } + return formatOptions; static void HandleStandardInput(ILogger logger, ref string[] include, ref string[] exclude) diff --git a/src/BuiltInTools/dotnet-format/Commands/FormatWhitespaceCommand.cs b/src/BuiltInTools/dotnet-format/Commands/FormatWhitespaceCommand.cs index 824038740604..40cf5379fe9b 100644 --- a/src/BuiltInTools/dotnet-format/Commands/FormatWhitespaceCommand.cs +++ b/src/BuiltInTools/dotnet-format/Commands/FormatWhitespaceCommand.cs @@ -22,6 +22,7 @@ internal static Command GetCommand() command.AddCommonOptions(); command.Validators.Add(EnsureFolderNotSpecifiedWithNoRestore); command.Validators.Add(EnsureFolderNotSpecifiedWhenLoggingBinlog); + command.Validators.Add(EnsureFolderNotSpecifiedWithFramework); command.Action = s_formattingHandler; return command; } @@ -46,6 +47,16 @@ internal static void EnsureFolderNotSpecifiedWhenLoggingBinlog(CommandResult sym } } + internal static void EnsureFolderNotSpecifiedWithFramework(CommandResult symbolResult) + { + var folder = symbolResult.GetValue(FolderOption); + var framework = symbolResult.GetResult(FrameworkOption); + if (folder && framework is not null && !framework.Implicit) + { + symbolResult.AddError(Resources.Cannot_specify_the_folder_option_with_framework); + } + } + private class FormatWhitespaceHandler : AsynchronousCommandLineAction { public override async Task InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken) diff --git a/src/BuiltInTools/dotnet-format/FormatOptions.cs b/src/BuiltInTools/dotnet-format/FormatOptions.cs index 7db0069bb474..0d291512680d 100644 --- a/src/BuiltInTools/dotnet-format/FormatOptions.cs +++ b/src/BuiltInTools/dotnet-format/FormatOptions.cs @@ -22,7 +22,8 @@ internal record FormatOptions( SourceFileMatcher FileMatcher, string? ReportPath, string? BinaryLogPath, - bool IncludeGeneratedFiles) + bool IncludeGeneratedFiles, + string? TargetFramework) { public static FormatOptions Instance = new( WorkspaceFilePath: null!, // must be supplied @@ -39,6 +40,7 @@ internal record FormatOptions( FileMatcher: SourceFileMatcher.CreateMatcher(Array.Empty(), Array.Empty()), ReportPath: null, BinaryLogPath: null, - IncludeGeneratedFiles: false); + IncludeGeneratedFiles: false, + TargetFramework: null); } } diff --git a/src/BuiltInTools/dotnet-format/Resources.resx b/src/BuiltInTools/dotnet-format/Resources.resx index ec627d90ce53..b54bf224c6a8 100644 --- a/src/BuiltInTools/dotnet-format/Resources.resx +++ b/src/BuiltInTools/dotnet-format/Resources.resx @@ -330,6 +330,12 @@ Cannot specify the '--folder' option when writing a binary log. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + + Cannot specify the '--folder' option with '--framework'. + PROJECT | SOLUTION diff --git a/src/BuiltInTools/dotnet-format/Utilities/DotNetHelper.cs b/src/BuiltInTools/dotnet-format/Utilities/DotNetHelper.cs index 6c8d18544f9b..99818ee139b2 100644 --- a/src/BuiltInTools/dotnet-format/Utilities/DotNetHelper.cs +++ b/src/BuiltInTools/dotnet-format/Utilities/DotNetHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Extensions.Logging; diff --git a/src/BuiltInTools/dotnet-format/Workspaces/MSBuildWorkspaceLoader.cs b/src/BuiltInTools/dotnet-format/Workspaces/MSBuildWorkspaceLoader.cs index 1ece23a46734..57bb28a91ec5 100644 --- a/src/BuiltInTools/dotnet-format/Workspaces/MSBuildWorkspaceLoader.cs +++ b/src/BuiltInTools/dotnet-format/Workspaces/MSBuildWorkspaceLoader.cs @@ -18,6 +18,7 @@ internal static class MSBuildWorkspaceLoader string? binaryLogPath, bool logWorkspaceWarnings, ILogger logger, + string? targetFramework, CancellationToken cancellationToken) { var properties = new Dictionary(StringComparer.Ordinal) @@ -28,6 +29,11 @@ internal static class MSBuildWorkspaceLoader { "AlwaysCompileMarkupFilesInSeparateDomain", bool.FalseString }, }; + if (targetFramework is not null) + { + properties["TargetFramework"] = targetFramework; + } + var workspace = MSBuildWorkspace.Create(properties); Build.Framework.ILogger? binlog = null; diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.cs.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.cs.xlf index f3a21d499b4d..bff1473b47a3 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.cs.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.cs.xlf @@ -62,6 +62,11 @@ Při spouštění analyzátorů není možné zadat možnost --folder. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. Není možné zadat možnost --folder s parametrem --no-restore. @@ -352,6 +357,11 @@ Naformátoval se soubor kódu {0}. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. Nepovedlo se opravit {0}. Oprava kódu {1} nevrátila akci Opravit vše. diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.de.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.de.xlf index 40a49347e259..3076b304bc15 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.de.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.de.xlf @@ -62,6 +62,11 @@ Die Option „--Ordner“ kann beim Ausführen von Analysetools nicht angegeben werden. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. Die Option „--Ordner“ kann nicht mit „--keine-Wiederherstellung“ angegeben werden. @@ -352,6 +357,11 @@ Codedatei "{0}" wurde formatiert. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. {0} kann nicht behoben werden. Codefix {1} hat keine Aktion „Alle korrigieren“ zurückgegeben. diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.es.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.es.xlf index 775cdef7cdf3..66c03769e6de 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.es.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.es.xlf @@ -62,6 +62,11 @@ No se puede especificar la opción "--folder" al ejecutar analizadores. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. No se puede especificar la opción "--folder" con "--no-restore". @@ -352,6 +357,11 @@ Archivo de código "{0}" con formato aplicado. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. No se puede corregir {0}. La corrección de código {1} no devolvió ninguna acción Corregir todo. diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.fr.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.fr.xlf index c29da3ec3b44..9c73f26606c8 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.fr.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.fr.xlf @@ -62,6 +62,11 @@ Impossible de spécifier l’option « --folder » lors de l’exécution des analyseurs. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. Impossible de spécifier l’option « --folder » avec « --no-restore ». @@ -352,6 +357,11 @@ Fichier de code '{0}' mis en forme. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. Impossible de corriger {0}. Le correctif de code {1} n’a pas retourné d’action Corriger tout. diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.it.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.it.xlf index 2aeb29336f18..fffc9751af7b 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.it.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.it.xlf @@ -62,6 +62,11 @@ Impossibile specificare l'opzione '--folder' durante l'esecuzione degli analizzatori. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. Non è possibile specificare l'opzione '--folder' con '--no-restore'. @@ -352,6 +357,11 @@ Il file di codice '{0}' è stato formattato. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. Impossibile correggere {0}. La correzione del codice {1} non ha restituito un'azione Correggi tutto. diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.ja.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.ja.xlf index 4cf225955ceb..94261f079d21 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.ja.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.ja.xlf @@ -62,6 +62,11 @@ アナライザーの実行時に '--folder' オプションを指定することはできません。 + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. '--folder' オプションを '--no-restore' と共に指定することはできません。 @@ -352,6 +357,11 @@ コード ファイル '{0}' がフォーマットされました。 + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. {0} を修正できません。コード修正 {1} は、[すべて修正] アクションを返しませんでした。 diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.ko.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.ko.xlf index 5fe1286052e1..82065400c1b8 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.ko.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.ko.xlf @@ -62,6 +62,11 @@ 분석기를 실행할 때는 '--folder' 옵션을 지정할 수 없습니다. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. '--no-restore'와 함께 '--folder' 옵션을 지정할 수 없습니다. @@ -352,6 +357,11 @@ 코드 파일 '{0}'의 서식을 지정했습니다. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. {0}을(를) 수정할 수 없습니다. 코드 수정 {1}에서 모두 수정 작업을 반환하지 않았습니다. diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.pl.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.pl.xlf index 37b8a4e1f484..b9d39f2b54cb 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.pl.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.pl.xlf @@ -62,6 +62,11 @@ Nie można określić opcji „--folder” podczas uruchamiania analizatorów. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. Nie można określić opcji „--folder” z parametrem „--no-restore”. @@ -352,6 +357,11 @@ Sformatowano plik kodu „{0}”. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. Nie można naprawić kodu {0}. Poprawka kodu {1} nie zwróciła akcji Napraw wszystko. diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.pt-BR.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.pt-BR.xlf index b57c3e3b44f4..55d09806aade 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.pt-BR.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.pt-BR.xlf @@ -62,6 +62,11 @@ Não é possível especificar a opção '--folder' ao executar analisadores. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. Não é possível especificar a opção '--folder' com '--no-restore'. @@ -352,6 +357,11 @@ Arquivo de código '{0}' formatado. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. Não é possível corrigir {0}. A correção de código {1} não retornou uma ação "Corrigir tudo". diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.ru.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.ru.xlf index 876497b11b1e..01b87364661c 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.ru.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.ru.xlf @@ -62,6 +62,11 @@ Невозможно указать параметр "--folder" при запуске анализаторов. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. Невозможно указать параметр "--folder" с "--no-restore". @@ -352,6 +357,11 @@ Отформатированный файл кода "{0}". + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. Не удалось исправить {0}. Исправление кода {1} не возвратило действие "Исправить все". diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.tr.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.tr.xlf index c20259208904..591a716f4bb5 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.tr.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.tr.xlf @@ -62,6 +62,11 @@ Çözümleyiciler çalıştırılırken '--folder' seçeneği belirtilemiyor. + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. '--no-restore' seçeneği ile '--folder' seçeneği belirtilemiyor. @@ -352,6 +357,11 @@ '{0}' kod dosyası biçimlendirildi. + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. {0} düzeltilemiyor. Kod düzeltmesi ({1}), Tümünü Düzelt eylemi döndürmedi. diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.zh-Hans.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.zh-Hans.xlf index 88482781e59c..46bd577ef432 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.zh-Hans.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.zh-Hans.xlf @@ -62,6 +62,11 @@ 运行分析器时无法指定 '--folder' 选项。 + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. 无法使用 '--no-restore' 指定 '--folder' 选项。 @@ -352,6 +357,11 @@ 已将代码文件“{0}”格式化。 + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. 无法修复 {0}。代码修复 {1} 未返回全部修复操作。 diff --git a/src/BuiltInTools/dotnet-format/xlf/Resources.zh-Hant.xlf b/src/BuiltInTools/dotnet-format/xlf/Resources.zh-Hant.xlf index 10d7cfa16699..92a98b25e489 100644 --- a/src/BuiltInTools/dotnet-format/xlf/Resources.zh-Hant.xlf +++ b/src/BuiltInTools/dotnet-format/xlf/Resources.zh-Hant.xlf @@ -62,6 +62,11 @@ 執行分析器時無法指定 '--folder' 選項。 + + Cannot specify the '--folder' option with '--framework'. + Cannot specify the '--folder' option with '--framework'. + + Cannot specify the '--folder' option with '--no-restore'. 無法指定 '--folder' 選項搭配 '--no-restore'。 @@ -352,6 +357,11 @@ 正在將程式碼檔案 '{0}' 格式化。 + + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + The target framework (TFM) to use when loading the workspace. Restricts restore and analysis to the specified framework only. + + Unable to fix {0}. Code fix {1} didn't return a Fix All action. 無法修正 {0}。程式碼修正 {1} 未傳回全部修正動作。 diff --git a/test/dotnet-format.UnitTests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs b/test/dotnet-format.UnitTests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs index 7063df88ef44..07fae27e9946 100644 --- a/test/dotnet-format.UnitTests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs +++ b/test/dotnet-format.UnitTests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs @@ -38,7 +38,7 @@ public async Task InitializeAsync() // Load the analyzer_project into a MSBuildWorkspace. var workspacePath = Path.Combine(TestProjectsPathHelper.GetProjectsDirectory(), s_analyzerProjectFilePath); - var analyzerWorkspace = await MSBuildWorkspaceLoader.LoadAsync(workspacePath, WorkspaceType.Project, binaryLogPath: null, logWorkspaceWarnings: true, logger, CancellationToken.None); + var analyzerWorkspace = await MSBuildWorkspaceLoader.LoadAsync(workspacePath, WorkspaceType.Project, binaryLogPath: null, logWorkspaceWarnings: true, logger, targetFramework: null, CancellationToken.None); TestOutputHelper.WriteLine(logger.GetLog()); diff --git a/test/dotnet-format.UnitTests/CodeFormatterTests.cs b/test/dotnet-format.UnitTests/CodeFormatterTests.cs index 235aab421456..8cc7da220915 100644 --- a/test/dotnet-format.UnitTests/CodeFormatterTests.cs +++ b/test/dotnet-format.UnitTests/CodeFormatterTests.cs @@ -696,7 +696,8 @@ internal async Task TestFormatWorkspaceAsync( fileMatcher, ReportPath: string.Empty, IncludeGeneratedFiles: includeGenerated, - BinaryLogPath: null); + BinaryLogPath: null, + TargetFramework: null); var formatResult = await CodeFormatter.FormatWorkspaceAsync(formatOptions, logger, CancellationToken.None); Environment.CurrentDirectory = currentDirectory; diff --git a/test/dotnet-format.UnitTests/Formatters/AbstractFormatterTests.cs b/test/dotnet-format.UnitTests/Formatters/AbstractFormatterTests.cs index 324c091956cb..29c24ac8dbf0 100644 --- a/test/dotnet-format.UnitTests/Formatters/AbstractFormatterTests.cs +++ b/test/dotnet-format.UnitTests/Formatters/AbstractFormatterTests.cs @@ -230,7 +230,8 @@ private protected async Task AssertCodeChangedAsync( fileMatcher, ReportPath: string.Empty, IncludeGeneratedFiles: false, - BinaryLogPath: null); + BinaryLogPath: null, + TargetFramework: null); var pathsToFormat = GetOnlyFileToFormat(solution); diff --git a/test/dotnet-format.UnitTests/Formatters/FormattedFilesTests.cs b/test/dotnet-format.UnitTests/Formatters/FormattedFilesTests.cs index a90554bbe170..7b615d43624b 100644 --- a/test/dotnet-format.UnitTests/Formatters/FormattedFilesTests.cs +++ b/test/dotnet-format.UnitTests/Formatters/FormattedFilesTests.cs @@ -72,7 +72,8 @@ private async Task> TestFormattedFiles(string testCode) fileMatcher, ReportPath: string.Empty, IncludeGeneratedFiles: false, - BinaryLogPath: null); + BinaryLogPath: null, + TargetFramework: null); var pathsToFormat = GetOnlyFileToFormat(solution); diff --git a/test/dotnet-format.UnitTests/MSBuild/MSBuildWorkspaceLoaderTests.cs b/test/dotnet-format.UnitTests/MSBuild/MSBuildWorkspaceLoaderTests.cs index 552401c2708e..d7bfa76f5d68 100644 --- a/test/dotnet-format.UnitTests/MSBuild/MSBuildWorkspaceLoaderTests.cs +++ b/test/dotnet-format.UnitTests/MSBuild/MSBuildWorkspaceLoaderTests.cs @@ -134,7 +134,7 @@ private static async Task AssertProjectLoadsCleanlyAsync(string projectFilePath, { var binaryLogPath = Path.ChangeExtension(projectFilePath, ".binlog"); - using var workspace = (MSBuildWorkspace)await MSBuildWorkspaceLoader.LoadAsync(projectFilePath, WorkspaceType.Project, binaryLogPath, logWorkspaceWarnings: true, logger, CancellationToken.None); + using var workspace = (MSBuildWorkspace)await MSBuildWorkspaceLoader.LoadAsync(projectFilePath, WorkspaceType.Project, binaryLogPath, logWorkspaceWarnings: true, logger, targetFramework: null, CancellationToken.None); Assert.Empty(workspace.Diagnostics); diff --git a/test/dotnet-format.UnitTests/ProgramTests.cs b/test/dotnet-format.UnitTests/ProgramTests.cs index c82189a13b09..04b7a49cfc80 100644 --- a/test/dotnet-format.UnitTests/ProgramTests.cs +++ b/test/dotnet-format.UnitTests/ProgramTests.cs @@ -1,9 +1,11 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable using Microsoft.CodeAnalysis.Tools.Commands; +using Microsoft.CodeAnalysis.Tools.Tests.Utilities; +using ProductionDotNetHelper = Microsoft.CodeAnalysis.Tools.Utilities.DotNetHelper; namespace Microsoft.CodeAnalysis.Tools.Tests { @@ -246,5 +248,76 @@ public void CommandLine_Diagnostics_DoesNotFailIfMultipleDiagnosticAreSpecified( // Assert Assert.Empty(result.Errors); } + + [Fact] + public void CommandLine_FrameworkOption_IsParsedCorrectly() + { + // Arrange + var sut = RootFormatCommand.GetCommand(); + + // Act + var result = sut.Parse(new[] { "--framework", "net8.0" }); + + // Assert + Assert.Empty(result.Errors); + Assert.Equal("net8.0", result.GetValue(FormatCommandCommon.FrameworkOption)); + } + + [Fact] + public void CommandLine_FrameworkOption_ShortAlias_IsParsedCorrectly() + { + // Arrange + var sut = RootFormatCommand.GetCommand(); + + // Act + var result = sut.Parse(new[] { "-f", "net8.0" }); + + // Assert + Assert.Empty(result.Errors); + Assert.Equal("net8.0", result.GetValue(FormatCommandCommon.FrameworkOption)); + } + + [Fact] + public void CommandLine_FolderValidation_FailsIfFrameworkSpecified() + { + // Arrange + var sut = RootFormatCommand.GetCommand(); + + // Act + var result = sut.Parse(new[] { "whitespace", "--folder", "--framework", "net8.0" }); + + // Assert + Assert.Single(result.Errors); + } + + [Fact] + public void ParseCommonOptions_FrameworkOption_SetsTargetFramework() + { + // Arrange + var sut = RootFormatCommand.GetCommand(); + var result = sut.Parse(new[] { "--framework", "net8.0" }); + var logger = new TestLogger(); + + // Act + var formatOptions = result.ParseCommonOptions(FormatOptions.Instance, logger); + + // Assert + Assert.Equal("net8.0", formatOptions.TargetFramework); + } + + [Fact] + public void ParseCommonOptions_NoFrameworkOption_LeavesTargetFrameworkNull() + { + // Arrange + var sut = RootFormatCommand.GetCommand(); + var result = sut.Parse(Array.Empty()); + var logger = new TestLogger(); + + // Act + var formatOptions = result.ParseCommonOptions(FormatOptions.Instance, logger); + + // Assert + Assert.Null(formatOptions.TargetFramework); + } } }