Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ internal void GenerateDepsJsonFile(
string? stdOut;
string? stdErr;

var msbuildArgs = MSBuildArgs.AnalyzeMSBuildArguments([..args], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandParser.TargetOption, BuildCommandParser.VerbosityOption);
var msbuildArgs = MSBuildArgs.AnalyzeMSBuildArguments([.. args], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandParser.TargetOption, BuildCommandParser.VerbosityOption);
var forwardingAppWithoutLogging = new MSBuildForwardingAppWithoutLogging(msbuildArgs, msBuildExePath);
if (forwardingAppWithoutLogging.ExecuteMSBuildOutOfProc)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Build/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class BuildCommand
{
public static CommandBase FromArgs(string[] args, string? msbuildPath = null)
{
var parseResult = Parser.Parse(["dotnet", "build", ..args]);
var parseResult = Parser.Parse(["dotnet", "build", .. args]);
return FromParseResult(parseResult, msbuildPath);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Cli/dotnet/Commands/Clean/CleanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CleanCommand(MSBuildArgs msbuildArgs, string? msbuildPath = null) :
{
public static CommandBase FromArgs(string[] args, string? msbuildPath = null)
{
var result = Parser.Parse(["dotnet", "clean", ..args]);
var result = Parser.Parse(["dotnet", "clean", .. args]);
return FromParseResult(result, msbuildPath);
}

Expand All @@ -33,7 +33,7 @@ public static CommandBase FromParseResult(ParseResult result, string? msbuildPat
NoWriteBuildMarkers = true,
},
static (msbuildArgs, msbuildPath) => new CleanCommand(msbuildArgs, msbuildPath),
[ CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandParser.TargetOption, CleanCommandParser.VerbosityOption ],
[CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandParser.TargetOption, CleanCommandParser.VerbosityOption],
result,
msbuildPath
);
Expand Down
6 changes: 6 additions & 0 deletions src/Cli/dotnet/Commands/CliCommandStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,12 @@ If not specified the file will be generated inside the default 'TestResults' dir
<data name="CmdSolutionPathName" xml:space="preserve">
<value>SOLUTION_PATH</value>
</data>
<data name="TestCmdProjectDescription" xml:space="preserve">
<value>Defines the path of the project file to test (folder name or full path). If not specified, it defaults to the current directory.</value>
</data>
<data name="TestCmdSolutionDescription" xml:space="preserve">
<value>Defines the path of the solution file to test (folder name or full path). If not specified, it defaults to the current directory.</value>
</data>
<data name="CmdSourceOption" xml:space="preserve">
<value>SOURCE</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Format/FormatCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FormatCommand(IEnumerable<string> argsToForward) : FormatForwarding
{
public static FormatCommand FromArgs(string[] args)
{
var result = Parser.Parse(["dotnet", "format", ..args]);
var result = Parser.Parse(["dotnet", "format", .. args]);
return FromParseResult(result);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Hidden/Complete/CompleteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static int Run(ParseResult parseResult)

public static int RunWithReporter(string[] args, IReporter reporter)
{
var result = Parser.Parse(["dotnet", "complete", ..args]);
var result = Parser.Parse(["dotnet", "complete", .. args]);
return RunWithReporter(result, reporter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static int Run(ParseResult parseResult)

public static void ProcessInputAndSendTelemetry(string[] args, ITelemetry telemetry)
{
var result = Parser.Parse(["dotnet", "internal-reportinstallsuccess", ..args]);
var result = Parser.Parse(["dotnet", "internal-reportinstallsuccess", .. args]);
ProcessInputAndSendTelemetry(result, telemetry);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Cli/dotnet/Commands/MSBuild/MSBuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace Microsoft.DotNet.Cli.Commands.MSBuild;
public class MSBuildCommand(
IEnumerable<string> msbuildArgs,
string? msbuildPath = null
) : MSBuildForwardingApp(MSBuildArgs.AnalyzeMSBuildArguments([..msbuildArgs], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, MSBuildCommandParser.TargetOption, CommonOptions.VerbosityOption()), msbuildPath, includeLogo: true)
) : MSBuildForwardingApp(MSBuildArgs.AnalyzeMSBuildArguments([.. msbuildArgs], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, MSBuildCommandParser.TargetOption, CommonOptions.VerbosityOption()), msbuildPath, includeLogo: true)
{
public static MSBuildCommand FromArgs(string[] args, string? msbuildPath = null)
{
var result = Parser.Parse(["dotnet", "msbuild", ..args]);
var result = Parser.Parse(["dotnet", "msbuild", .. args]);
return FromParseResult(result, msbuildPath);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Cli/dotnet/Commands/Pack/PackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PackCommand(
{
public static CommandBase FromArgs(string[] args, string? msbuildPath = null)
{
var parseResult = Parser.Parse(["dotnet", "pack", ..args]);
var parseResult = Parser.Parse(["dotnet", "pack", .. args]);
return FromParseResult(parseResult, msbuildPath);
}

Expand Down Expand Up @@ -92,14 +92,14 @@ public static int RunPackCommand(ParseResult parseResult)

if (args.Count != 1)
{
Console.Error.WriteLine(CliStrings.PackCmd_OneNuspecAllowed);
Console.Error.WriteLine(CliStrings.PackCmd_OneNuspecAllowed);
return 1;
}

var nuspecPath = args[0];

var packArgs = new PackArgs()
{
{
Logger = new NuGetConsoleLogger(),
Exclude = new List<string>(),
OutputDirectory = parseResult.GetValue(PackCommandParser.OutputOption),
Expand Down
4 changes: 2 additions & 2 deletions src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#nullable disable

using System.CommandLine;
using System.Globalization;
using Microsoft.DotNet.Cli.Commands.Hidden.List;
using Microsoft.DotNet.Cli.Commands.MSBuild;
using Microsoft.DotNet.Cli.Commands.NuGet;
using Microsoft.DotNet.Cli.Extensions;
using Microsoft.DotNet.Cli.Utils;
using System.Globalization;
using Microsoft.DotNet.Cli.Commands.MSBuild;

namespace Microsoft.DotNet.Cli.Commands.Package.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#nullable disable

using System.CommandLine;
using Microsoft.DotNet.Cli.Commands.NuGet;
using Microsoft.DotNet.Cli.Extensions;
using System.CommandLine;

namespace Microsoft.DotNet.Cli.Commands.Package.Search;

Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Publish/PublishCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private PublishCommand(

public static CommandBase FromArgs(string[] args, string? msbuildPath = null)
{
var parseResult = Parser.Parse(["dotnet", "publish", ..args]);
var parseResult = Parser.Parse(["dotnet", "publish", .. args]);
return FromParseResult(parseResult);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Restore/RestoreCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class RestoreCommand
{
public static CommandBase FromArgs(string[] args, string? msbuildPath = null)
{
var result = Parser.Parse(["dotnet", "restore", ..args]);
var result = Parser.Parse(["dotnet", "restore", .. args]);
return FromParseResult(result, msbuildPath);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Cli/dotnet/Commands/Restore/RestoringCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RestoringCommand(
string? msbuildPath = null,
string? userProfileDir = null,
bool? advertiseWorkloadUpdates = null)
: base(GetCommandArguments(msbuildArgs, noRestore), msbuildPath)
: base(GetCommandArguments(msbuildArgs, noRestore), msbuildPath)
{
userProfileDir = CliFolderPathCalculator.DotnetUserProfileFolderPath;
Task.Run(() => WorkloadManifestUpdater.BackgroundUpdateAdvertisingManifestsAsync(userProfileDir));
Expand Down Expand Up @@ -122,13 +122,13 @@ private static MSBuildArgs GetCommandArguments(
ReadOnlyDictionary<string, string> restoreProperties =
msbuildArgs.GlobalProperties?
.Where(kvp => !IsPropertyExcludedFromRestore(kvp.Key))?
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase) is { } filteredList ? new(filteredList): ReadOnlyDictionary<string, string>.Empty;
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase) is { } filteredList ? new(filteredList) : ReadOnlyDictionary<string, string>.Empty;
var restoreMSBuildArgs =
MSBuildArgs.FromProperties(RestoreOptimizationProperties)
.CloneWithAdditionalTargets("Restore")
.CloneWithExplicitArgs([.. newArgumentsToAdd, .. existingArgumentsToForward])
.CloneWithAdditionalProperties(restoreProperties);
if (msbuildArgs.Verbosity is {} verbosity)
if (msbuildArgs.Verbosity is { } verbosity)
{
restoreMSBuildArgs = restoreMSBuildArgs.CloneWithVerbosity(verbosity);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ private static bool HasPropertyToExcludeFromRestore(MSBuildArgs msbuildArgs)

private static readonly List<string> FlagsThatTriggerSilentSeparateRestore = [.. ComputeFlags(FlagsThatTriggerSilentRestore)];

private static readonly List<string> PropertiesToExcludeFromSeparateRestore = [ .. PropertiesToExcludeFromRestore ];
private static readonly List<string> PropertiesToExcludeFromSeparateRestore = [.. PropertiesToExcludeFromRestore];

/// <summary>
/// We investigate the arguments we're about to send to a separate restore call and filter out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSett
{
if (prop.Value.TryGetProperty(CommandNameKey, out var commandNameElement) && commandNameElement.ValueKind == JsonValueKind.String)
{
if (commandNameElement.GetString() is { } commandNameElementKey && _providers.ContainsKey(commandNameElementKey))
if (commandNameElement.GetString() is { } commandNameElementKey && _providers.ContainsKey(commandNameElementKey))
{
profileObject = prop.Value;
break;
Expand Down Expand Up @@ -120,7 +120,7 @@ public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSett
}
}

private static bool TryLocateHandler(string? commandName, [NotNullWhen(true)]out ILaunchSettingsProvider? provider)
private static bool TryLocateHandler(string? commandName, [NotNullWhen(true)] out ILaunchSettingsProvider? provider)
{
if (commandName == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Run/RunTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,4 @@ private static bool IsDefaultProfile(string? profileName)
// The default profile name at this point is "(Default)"
return profileName.Equals("(Default)", StringComparison.OrdinalIgnoreCase);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public override int Execute()
{
ConvertToSlnxAsync(slnFileFullPath, slnxFileFullPath, CancellationToken.None).Wait();
return 0;
} catch (Exception ex) {
}
catch (Exception ex)
{
throw new GracefulException(ex.Message, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static async Task RemoveProjectsAsync(string solutionFileFullPath, IEnum
{
solution.RemoveFolder(folder);
// After removal, adjust index and continue to avoid skipping folders after removal
i--;
i--;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Store/StoreCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private StoreCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)

public static StoreCommand FromArgs(string[] args, string msbuildPath = null)
{
var result = Parser.Parse(["dotnet", "store", ..args]);
var result = Parser.Parse(["dotnet", "store", .. args]);
return FromParseResult(result, msbuildPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ internal static class MicrosoftTestingPlatformOptions
{
public static readonly Option<string> ProjectOption = new("--project")
{
Description = CliCommandStrings.CmdProjectDescription,
Description = CliCommandStrings.TestCmdProjectDescription,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a minor nit: the strings for run and test are the same except for the 'verb' used - we've been extracting this pattern out to shared strings and providing the 'verb' as a parameter when creating the Option/Argument.

@copilot can you extract the shared loc string and update the test and run usages of the Project and Solution options to use the shared string, passing in the matching verb?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baronfel Is it fine if the words "run"/"test" are not localized? Or do we want to also have resources with "single" words for "run" and "test" so they are localized?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point - @copilot make those single words localizeable as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 99e653e. Created parameterized resource strings CmdProjectDescriptionFormat and CmdSolutionDescriptionFormat, and factory methods CommonOptions.ProjectOption(string verb) and CommonOptions.SolutionOption(string verb). Both test and run commands now use these shared methods with their respective verbs ("test" and "run").

Test command:

--project <PROJECT_PATH>    Defines the path of the project file to test. Use path to the project file, or 
                            path to the directory containing the project file. If not specified, it 
                            defaults to the current directory.

Run command:

--project <PROJECT_PATH>    Defines the path of the project file to run. Use path to the project file, or 
                            path to the directory containing the project file. If not specified, it 
                            defaults to the current directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit d8074b5. Added localized verb resources VerbRun and VerbTest in CliCommandStrings.resx. Updated both test and run command parsers to use these localized strings instead of hardcoded "test" and "run".

Changes:

  • Created VerbRun and VerbTest resource strings
  • Updated MicrosoftTestingPlatformOptions to use CliCommandStrings.VerbTest
  • Updated RunCommandParser to use CliCommandStrings.VerbRun

The verbs are now properly localizable, ensuring consistent translations across all languages.

HelpName = CliCommandStrings.CmdProjectPathName,
Arity = ArgumentArity.ExactlyOne
};

public static readonly Option<string> SolutionOption = new("--solution")
{
Description = CliCommandStrings.CmdSolutionDescription,
Description = CliCommandStrings.TestCmdSolutionDescription,
HelpName = CliCommandStrings.CmdSolutionPathName,
Arity = ArgumentArity.ExactlyOne
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Concurrent;
using Microsoft.TemplateEngine.Cli.Help;
using System.Globalization;
using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis;
using Microsoft.Testing.Platform.OutputDevice.Terminal;
using Microsoft.DotNet.Cli.Commands.Test.IPC.Models;
using Microsoft.TemplateEngine.Cli.Help;
using Microsoft.Testing.Platform.OutputDevice.Terminal;

namespace Microsoft.DotNet.Cli.Commands.Test.Terminal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private async Task Read(BuildOptions buildOptions, TestOptions testOptions, Term
{
result = ExitCode.GenericFailure;
}

lock (_lock)
{
if (_aggregateExitCode is null)
Expand Down
9 changes: 5 additions & 4 deletions src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static int ForwardToVSTestConsole(ParseResult parseResult, string[] args

public static TestCommand FromArgs(string[] args, string? testSessionCorrelationId = null, string? msbuildPath = null)
{
var parseResult = Parser.Parse(["dotnet", "test", ..args]);
var parseResult = Parser.Parse(["dotnet", "test", .. args]);

// settings parameters are after -- (including --), these should not be considered by the parser
string[] settings = [.. args.SkipWhile(a => a != "--")];
Expand Down Expand Up @@ -239,9 +239,10 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings
}
}


Dictionary<string, string> variables = VSTestForwardingApp.GetVSTestRootVariables();
foreach (var (rootVariableName, rootValue) in variables) {
foreach (var (rootVariableName, rootValue) in variables)
{
testCommand.EnvironmentVariable(rootVariableName, rootValue);
VSTestTrace.SafeWriteTrace(() => $"Root variable set {rootVariableName}:{rootValue}");
}
Expand Down Expand Up @@ -303,7 +304,7 @@ private static bool ContainsBuiltTestSources(string[] args)
if (arg.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || arg.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
{
var previousArg = i > 0 ? args[i - 1] : null;
if (previousArg != null && CommonOptions.PropertiesOption.Aliases.Contains(previousArg))
if (previousArg != null && CommonOptions.PropertiesOption.Aliases.Contains(previousArg))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Test/VSTest/VSTestForwardingApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public VSTestForwardingApp(IEnumerable<string> argsToForward)
WithEnvironmentVariable(rootVariableName, rootValue);
VSTestTrace.SafeWriteTrace(() => $"Root variable set {rootVariableName}:{rootValue}");
}

VSTestTrace.SafeWriteTrace(() => $"Forwarding to '{GetVSTestExePath()}' with args \"{argsToForward?.Aggregate((a, b) => $"{a} | {b}")}\"");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

using System.CommandLine;
using System.Transactions;
using Microsoft.DotNet.Cli.Commands.Tool.Common;
using Microsoft.DotNet.Cli.Commands.Tool.List;
using Microsoft.DotNet.Cli.Commands.Tool.Uninstall;
using Microsoft.DotNet.Cli.Commands.Tool.Update;
using Microsoft.DotNet.Cli.Extensions;
using Microsoft.DotNet.Cli.NuGetPackageDownloader;
using Microsoft.DotNet.Cli.ShellShim;
using Microsoft.DotNet.Cli.ToolPackage;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Cli.Utils.Extensions;
using Microsoft.Extensions.EnvironmentAbstractions;
using NuGet.Common;
using NuGet.Frameworks;
using NuGet.Versioning;
using Microsoft.DotNet.Cli.Utils.Extensions;
using Microsoft.DotNet.Cli.Extensions;
using Microsoft.DotNet.Cli.ShellShim;
using Microsoft.DotNet.Cli.Commands.Tool.Update;
using Microsoft.DotNet.Cli.Commands.Tool.Common;
using Microsoft.DotNet.Cli.Commands.Tool.Uninstall;
using Microsoft.DotNet.Cli.Commands.Tool.List;

namespace Microsoft.DotNet.Cli.Commands.Tool.Install;

Expand Down Expand Up @@ -187,7 +187,7 @@ private int ExecuteInstallCommand(PackageId packageId)
{
_reporter.WriteLine(string.Format(CliCommandStrings.ToolAlreadyInstalled, oldPackageNullable.Id, oldPackageNullable.Version.ToNormalizedString()).Green());
return 0;
}
}
}

TransactionalAction.Run(() =>
Expand Down Expand Up @@ -318,7 +318,7 @@ private static void RunWithHandlingUninstallError(Action uninstallAction, Packag
{
try
{
uninstallAction();
uninstallAction();
}
catch (Exception ex)
when (ToolUninstallCommandLowLevelErrorConverter.ShouldConvertToUserFacingError(ex))
Expand Down Expand Up @@ -396,7 +396,7 @@ private void PrintSuccessMessage(IToolPackage oldPackage, IToolPackage newInstal
{
_reporter.WriteLine(
string.Format(

newInstalledPackage.Version.IsPrerelease ?
CliCommandStrings.UpdateSucceededPreVersionNoChange : CliCommandStrings.UpdateSucceededStableVersionNoChange,
newInstalledPackage.Id, newInstalledPackage.Version).Green());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override int Execute()
}
else
{
return ExecuteInstallCommand((PackageId) _packageId);
return ExecuteInstallCommand((PackageId)_packageId);
}
}

Expand Down
Loading
Loading