Merge pull request #5067 from piotrpMSFT/piotrpMSFT/locpass

Localize CLI command line parser
This commit is contained in:
Livar 2016-12-17 10:06:09 -08:00 committed by GitHub
commit 9ad164a9dd
52 changed files with 635 additions and 184 deletions

View file

@ -0,0 +1,19 @@
namespace Microsoft.DotNet.Cli.Sln.Internal
{
internal class LocalizableStrings
{
public const string GlobalSectionMoreThanOnceError = "Global section specified more than once";
public const string GlobalSectionNotClosedError = "Global section not closed";
public const string FileHeaderMissingError = "File header is missing";
public const string ProjectSectionNotClosedError = "Project section not closed";
public const string InvalidSectionTypeError = "Invalid section type: {0}";
public const string SectionIdMissingError = "Section id missing";
public const string ClosingSectionTagNotFoundError = "Closing section tag not found";
}
}

View file

@ -157,7 +157,7 @@ namespace Microsoft.DotNet.Cli.Sln.Internal
{ {
if (globalFound) if (globalFound)
{ {
throw new InvalidSolutionFormatException(curLineNum, "Global section specified more than once"); throw new InvalidSolutionFormatException(curLineNum, LocalizableStrings.GlobalSectionMoreThanOnceError);
} }
globalFound = true; globalFound = true;
while ((line = reader.ReadLine()) != null) while ((line = reader.ReadLine()) != null)
@ -181,7 +181,7 @@ namespace Microsoft.DotNet.Cli.Sln.Internal
} }
if (line == null) if (line == null)
{ {
throw new InvalidSolutionFormatException(curLineNum, "Global section not closed"); throw new InvalidSolutionFormatException(curLineNum, LocalizableStrings.GlobalSectionNotClosedError);
} }
} }
else if (line.IndexOf('=') != -1) else if (line.IndexOf('=') != -1)
@ -191,7 +191,7 @@ namespace Microsoft.DotNet.Cli.Sln.Internal
} }
if (FormatVersion == null) if (FormatVersion == null)
{ {
throw new InvalidSolutionFormatException(curLineNum, "File header is missing"); throw new InvalidSolutionFormatException(curLineNum, LocalizableStrings.FileHeaderMissingError);
} }
} }
@ -318,7 +318,7 @@ namespace Microsoft.DotNet.Cli.Sln.Internal
} }
} }
throw new InvalidSolutionFormatException(curLineNum, "Project section not closed"); throw new InvalidSolutionFormatException(curLineNum, LocalizableStrings.ProjectSectionNotClosedError);
} }
private void FindNext(int ln, string line, ref int i, char c) private void FindNext(int ln, string line, ref int i, char c)
@ -468,7 +468,7 @@ namespace Microsoft.DotNet.Cli.Sln.Internal
{ {
return SlnSectionType.PostProcess; return SlnSectionType.PostProcess;
} }
throw new InvalidSolutionFormatException(curLineNum, "Invalid section type: " + s); throw new InvalidSolutionFormatException(curLineNum, String.Format(LocalizableStrings.InvalidSectionTypeError, s));
} }
private string FromSectionType(bool isProjectSection, SlnSectionType type) private string FromSectionType(bool isProjectSection, SlnSectionType type)
@ -489,7 +489,7 @@ namespace Microsoft.DotNet.Cli.Sln.Internal
int k = line.IndexOf('('); int k = line.IndexOf('(');
if (k == -1) if (k == -1)
{ {
throw new InvalidSolutionFormatException(curLineNum, "Section id missing"); throw new InvalidSolutionFormatException(curLineNum, LocalizableStrings.SectionIdMissingError);
} }
var tag = line.Substring(0, k).Trim(); var tag = line.Substring(0, k).Trim();
var k2 = line.IndexOf(')', k); var k2 = line.IndexOf(')', k);
@ -518,7 +518,7 @@ namespace Microsoft.DotNet.Cli.Sln.Internal
} }
if (line == null) if (line == null)
{ {
throw new InvalidSolutionFormatException(curLineNum, "Closing section tag not found"); throw new InvalidSolutionFormatException(curLineNum, LocalizableStrings.ClosingSectionTagNotFoundError);
} }
} }

View file

@ -118,7 +118,10 @@ namespace Microsoft.DotNet.Cli.Utils
public CommandResult Execute() public CommandResult Execute()
{ {
Reporter.Verbose.WriteLine($"Running {_process.StartInfo.FileName} {_process.StartInfo.Arguments}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.RunningFileNameArguments,
_process.StartInfo.FileName,
_process.StartInfo.Arguments));
ThrowIfRunning(); ThrowIfRunning();
@ -135,7 +138,9 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
_process.Start(); _process.Start();
Reporter.Verbose.WriteLine($"Process ID: {_process.Id}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.ProcessId,
_process.Id));
var taskOut = _stdOut?.BeginRead(_process.StandardOutput); var taskOut = _stdOut?.BeginRead(_process.StandardOutput);
var taskErr = _stdErr?.BeginRead(_process.StandardError); var taskErr = _stdErr?.BeginRead(_process.StandardError);
@ -148,7 +153,11 @@ namespace Microsoft.DotNet.Cli.Utils
var exitCode = _process.ExitCode; var exitCode = _process.ExitCode;
#if DEBUG #if DEBUG
var message = $"< {FormatProcessInfo(_process.StartInfo)} exited with {exitCode} in {sw.ElapsedMilliseconds} ms."; var message = string.Format(
LocalizableStrings.ProcessExitedWithCode,
FormatProcessInfo(_process.StartInfo),
exitCode,
sw.ElapsedMilliseconds);
if (exitCode == 0) if (exitCode == 0)
{ {
Reporter.Verbose.WriteLine(message.Green()); Reporter.Verbose.WriteLine(message.Green());
@ -288,7 +297,9 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
if (_running) if (_running)
{ {
throw new InvalidOperationException($"Unable to invoke {memberName} after the command has been run"); throw new InvalidOperationException(string.Format(
LocalizableStrings.UnableToInvokeMemberNameAfterCommand,
memberName));
} }
} }
} }

View file

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Cli.Utils.CommandParsing namespace Microsoft.DotNet.Cli.Utils.CommandParsing
{ {
@ -54,7 +55,7 @@ namespace Microsoft.DotNet.Cli.Utils.CommandParsing
var result = grammar.Parse(cursor); var result = grammar.Parse(cursor);
if (!result.Remainder.IsEnd) if (!result.Remainder.IsEnd)
{ {
throw new ArgumentException($"Malformed command text '{text}'", nameof(text)); throw new ArgumentException(string.Format(LocalizableStrings.MalformedText, nameof(text)));
} }
return result.Value.ToArray(); return result.Value.ToArray();
} }

View file

@ -59,7 +59,8 @@ namespace Microsoft.DotNet.Cli.Utils
if (!Directory.Exists(buildOutputPath)) if (!Directory.Exists(buildOutputPath))
{ {
Reporter.Verbose.WriteLine($"outputpathresolver: {buildOutputPath} does not exist"); Reporter.Verbose.WriteLine(
string.Format(LocalizableStrings.BuildOutputPathDoesNotExist, buildOutputPath));
return null; return null;
} }

View file

@ -10,6 +10,8 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
public class PackagedCommandSpecFactory : IPackagedCommandSpecFactory public class PackagedCommandSpecFactory : IPackagedCommandSpecFactory
{ {
private const string PackagedCommandSpecFactoryName = "packagedcommandspecfactory";
private Action<string, IList<string>> _addAdditionalArguments; private Action<string, IList<string>> _addAdditionalArguments;
internal PackagedCommandSpecFactory(Action<string, IList<string>> addAdditionalArguments = null) internal PackagedCommandSpecFactory(Action<string, IList<string>> addAdditionalArguments = null)
@ -27,14 +29,21 @@ namespace Microsoft.DotNet.Cli.Utils
string depsFilePath, string depsFilePath,
string runtimeConfigPath) string runtimeConfigPath)
{ {
Reporter.Verbose.WriteLine($"packagedcommandspecfactory: attempting to find command {commandName} in {toolLibrary.Name}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.AttemptingToFindCommand,
PackagedCommandSpecFactoryName,
commandName,
toolLibrary.Name));
var toolAssembly = toolLibrary?.RuntimeAssemblies var toolAssembly = toolLibrary?.RuntimeAssemblies
.FirstOrDefault(r => Path.GetFileNameWithoutExtension(r.Path) == commandName); .FirstOrDefault(r => Path.GetFileNameWithoutExtension(r.Path) == commandName);
if (toolAssembly == null) if (toolAssembly == null)
{ {
Reporter.Verbose.WriteLine($"packagedcommandspecfactory: failed to find toolAssembly for {commandName}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.FailedToFindToolAssembly,
PackagedCommandSpecFactoryName,
commandName));
return null; return null;
} }
@ -43,7 +52,10 @@ namespace Microsoft.DotNet.Cli.Utils
if (!File.Exists(commandPath)) if (!File.Exists(commandPath))
{ {
Reporter.Verbose.WriteLine($"packagedcommandspecfactory: failed to find commandPath {commandPath}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.FailedToFindCommandPath,
PackagedCommandSpecFactoryName,
commandPath));
return null; return null;
} }
@ -57,12 +69,17 @@ namespace Microsoft.DotNet.Cli.Utils
runtimeConfigPath); runtimeConfigPath);
} }
private string GetCommandFilePath(string nugetPackagesRoot, LockFileTargetLibrary toolLibrary, LockFileItem runtimeAssembly) private string GetCommandFilePath(
string nugetPackagesRoot,
LockFileTargetLibrary toolLibrary,
LockFileItem runtimeAssembly)
{ {
var packageDirectory = new VersionFolderPathResolver(nugetPackagesRoot) var packageDirectory = new VersionFolderPathResolver(nugetPackagesRoot)
.GetInstallPath(toolLibrary.Name, toolLibrary.Version); .GetInstallPath(toolLibrary.Name, toolLibrary.Version);
var filePath = Path.Combine(packageDirectory, PathUtility.GetPathWithDirectorySeparator(runtimeAssembly.Path)); var filePath = Path.Combine(
packageDirectory,
PathUtility.GetPathWithDirectorySeparator(runtimeAssembly.Path));
return filePath; return filePath;
} }
@ -107,7 +124,7 @@ namespace Microsoft.DotNet.Cli.Utils
host = muxer.MuxerPath; host = muxer.MuxerPath;
if (host == null) if (host == null)
{ {
throw new Exception("Unable to locate dotnet multiplexer"); throw new Exception(LocalizableStrings.UnableToLocateDotnetMultiplexer);
} }
arguments.Add("exec"); arguments.Add("exec");

View file

@ -30,7 +30,10 @@ namespace Microsoft.DotNet.Cli.Utils
var preferCliRuntimePath = Path.Combine(packageDirectory, "prefercliruntime"); var preferCliRuntimePath = Path.Combine(packageDirectory, "prefercliruntime");
Reporter.Verbose.WriteLine( Reporter.Verbose.WriteLine(
$"packagedcommandspecfactory: Looking for prefercliruntime file at `{preferCliRuntimePath}`"); string.Format(
LocalizableStrings.LookingForPreferCliRuntimeFile,
"packagedcommandspecfactory",
preferCliRuntimePath));
return File.Exists(preferCliRuntimePath); return File.Exists(preferCliRuntimePath);
} }

View file

@ -10,6 +10,8 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
public class ProjectDependenciesCommandResolver : ICommandResolver public class ProjectDependenciesCommandResolver : ICommandResolver
{ {
private const string ProjectDependenciesCommandResolverName = "projectdependenciescommandresolver";
private static readonly CommandResolutionStrategy s_commandResolutionStrategy = private static readonly CommandResolutionStrategy s_commandResolutionStrategy =
CommandResolutionStrategy.ProjectDependenciesPackage; CommandResolutionStrategy.ProjectDependenciesPackage;
@ -36,14 +38,19 @@ namespace Microsoft.DotNet.Cli.Utils
public CommandSpec Resolve(CommandResolverArguments commandResolverArguments) public CommandSpec Resolve(CommandResolverArguments commandResolverArguments)
{ {
Reporter.Verbose.WriteLine($"projectdependenciescommandresolver: attempting to resolve {commandResolverArguments.CommandName}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.AttemptingToResolve,
ProjectDependenciesCommandResolverName,
commandResolverArguments.CommandName));
if (commandResolverArguments.Framework == null if (commandResolverArguments.Framework == null
|| commandResolverArguments.ProjectDirectory == null || commandResolverArguments.ProjectDirectory == null
|| commandResolverArguments.Configuration == null || commandResolverArguments.Configuration == null
|| commandResolverArguments.CommandName == null) || commandResolverArguments.CommandName == null)
{ {
Reporter.Verbose.WriteLine($"projectdependenciescommandresolver: invalid commandResolverArguments"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.InvalidCommandResolverArguments,
ProjectDependenciesCommandResolverName));
return null; return null;
} }
@ -79,7 +86,10 @@ namespace Microsoft.DotNet.Cli.Utils
if (project == null) if (project == null)
{ {
Reporter.Verbose.WriteLine($"projectdependenciescommandresolver: Didn't find a matching project {projectDirectory}."); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.DidNotFindAMatchingProject,
ProjectDependenciesCommandResolverName,
projectDirectory));
return null; return null;
} }
@ -87,7 +97,10 @@ namespace Microsoft.DotNet.Cli.Utils
if (!File.Exists(depsFilePath)) if (!File.Exists(depsFilePath))
{ {
Reporter.Verbose.WriteLine($"projectdependenciescommandresolver: {depsFilePath} does not exist"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.DoesNotExist,
ProjectDependenciesCommandResolverName,
depsFilePath));
return null; return null;
} }
@ -95,7 +108,10 @@ namespace Microsoft.DotNet.Cli.Utils
if (!File.Exists(runtimeConfigPath)) if (!File.Exists(runtimeConfigPath))
{ {
Reporter.Verbose.WriteLine($"projectdependenciescommandresolver: {runtimeConfigPath} does not exist"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.DoesNotExist,
ProjectDependenciesCommandResolverName,
runtimeConfigPath));
return null; return null;
} }
@ -130,10 +146,15 @@ namespace Microsoft.DotNet.Cli.Utils
if (toolLibraries?.Count() > 1) if (toolLibraries?.Count() > 1)
{ {
throw new InvalidOperationException($"Ambiguous command name: {commandName}"); throw new InvalidOperationException(string.Format(
LocalizableStrings.AmbiguousCommandName,
commandName));
} }
Reporter.Verbose.WriteLine($"projectdependenciescommandresolver: tool library found {toolLibraries?.Count() > 0}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.ToolLibraryFound,
ProjectDependenciesCommandResolverName,
toolLibraries?.Count() > 0));
return toolLibraries?.FirstOrDefault(); return toolLibraries?.FirstOrDefault();
} }

View file

@ -12,6 +12,8 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
internal class ProjectFactory internal class ProjectFactory
{ {
private const string ProjectFactoryName = "projectfactory";
private IEnvironmentProvider _environment; private IEnvironmentProvider _environment;
public ProjectFactory(IEnvironmentProvider environment) public ProjectFactory(IEnvironmentProvider environment)
@ -37,11 +39,17 @@ namespace Microsoft.DotNet.Cli.Utils
Path.Combine(AppContext.BaseDirectory, "MSBuild.dll") : Path.Combine(AppContext.BaseDirectory, "MSBuild.dll") :
msBuildExePath; msBuildExePath;
Reporter.Verbose.WriteLine($"projectfactory: MSBUILD_EXE_PATH = {msBuildExePath}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.MSBuildExePath,
ProjectFactoryName,
msBuildExePath));
string msBuildProjectPath = GetMSBuildProjPath(projectDirectory); string msBuildProjectPath = GetMSBuildProjPath(projectDirectory);
Reporter.Verbose.WriteLine($"projectfactory: MSBuild project path = {msBuildProjectPath}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.MSBuildProjectPath,
ProjectFactoryName,
msBuildProjectPath));
if(msBuildProjectPath == null) if(msBuildProjectPath == null)
{ {
@ -72,8 +80,9 @@ namespace Microsoft.DotNet.Cli.Utils
} }
else if (projectFiles.Count() > 1) else if (projectFiles.Count() > 1)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(string.Format(
$"Specify which project file to use because this '{projectDirectory}' contains more than one project file."); LocalizableStrings.MultipleProjectFilesFound,
projectDirectory));
} }
return projectFiles.First(); return projectFiles.First();

View file

@ -16,6 +16,8 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
public class ProjectToolsCommandResolver : ICommandResolver public class ProjectToolsCommandResolver : ICommandResolver
{ {
private const string ProjectToolsCommandResolverName = "projecttoolscommandresolver";
private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetCoreApp10; private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetCoreApp10;
private static readonly CommandResolutionStrategy s_commandResolutionStrategy = private static readonly CommandResolutionStrategy s_commandResolutionStrategy =
@ -44,7 +46,9 @@ namespace Microsoft.DotNet.Cli.Utils
if (commandResolverArguments.CommandName == null if (commandResolverArguments.CommandName == null
|| commandResolverArguments.ProjectDirectory == null) || commandResolverArguments.ProjectDirectory == null)
{ {
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: Invalid CommandResolverArguments"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.InvalidCommandResolverArguments,
ProjectToolsCommandResolverName));
return null; return null;
} }
@ -65,7 +69,8 @@ namespace Microsoft.DotNet.Cli.Utils
if (project == null) if (project == null)
{ {
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: ProjectFactory did not find Project."); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.DidNotFindProject, ProjectToolsCommandResolverName));
return null; return null;
} }
@ -85,7 +90,10 @@ namespace Microsoft.DotNet.Cli.Utils
IEnumerable<string> args, IEnumerable<string> args,
IProject project) IProject project)
{ {
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: resolving commandspec from {toolsLibraries.Count()} Tool Libraries."); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.ResolvingCommandSpec,
ProjectToolsCommandResolverName,
toolsLibraries.Count()));
foreach (var toolLibrary in toolsLibraries) foreach (var toolLibrary in toolsLibraries)
{ {
@ -101,7 +109,9 @@ namespace Microsoft.DotNet.Cli.Utils
} }
} }
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: failed to resolve commandspec from library."); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.FailedToResolveCommandSpec,
ProjectToolsCommandResolverName));
return null; return null;
} }
@ -112,17 +122,26 @@ namespace Microsoft.DotNet.Cli.Utils
IEnumerable<string> args, IEnumerable<string> args,
IProject project) IProject project)
{ {
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: Attempting to resolve command spec from tool {toolLibraryRange.Name}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.AttemptingToResolveCommandSpec,
ProjectToolsCommandResolverName,
toolLibraryRange.Name));
var nuGetPathContext = NuGetPathContext.Create(project.ProjectRoot); var nuGetPathContext = NuGetPathContext.Create(project.ProjectRoot);
var nugetPackagesRoot = nuGetPathContext.UserPackageFolder; var nugetPackagesRoot = nuGetPathContext.UserPackageFolder;
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: nuget packages root:\n{nugetPackagesRoot}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.NuGetPackagesRoot,
ProjectToolsCommandResolverName,
nugetPackagesRoot));
var toolLockFile = GetToolLockFile(toolLibraryRange, nugetPackagesRoot); var toolLockFile = GetToolLockFile(toolLibraryRange, nugetPackagesRoot);
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: found tool lockfile at : {toolLockFile.Path}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.FoundToolLockFile,
ProjectToolsCommandResolverName,
toolLockFile.Path));
var toolLibrary = toolLockFile.Targets var toolLibrary = toolLockFile.Targets
.FirstOrDefault( .FirstOrDefault(
@ -131,7 +150,9 @@ namespace Microsoft.DotNet.Cli.Utils
if (toolLibrary == null) if (toolLibrary == null)
{ {
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: library not found in lock file."); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.LibraryNotFoundInLockFile,
ProjectToolsCommandResolverName));
return null; return null;
} }
@ -142,7 +163,9 @@ namespace Microsoft.DotNet.Cli.Utils
var normalizedNugetPackagesRoot = PathUtility.EnsureNoTrailingDirectorySeparator(nugetPackagesRoot); var normalizedNugetPackagesRoot = PathUtility.EnsureNoTrailingDirectorySeparator(nugetPackagesRoot);
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: attempting to create commandspec"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.AttemptingToCreateCommandSpec,
ProjectToolsCommandResolverName));
var commandSpec = _packagedCommandSpecFactory.CreateCommandSpecFromLibrary( var commandSpec = _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
toolLibrary, toolLibrary,
@ -156,7 +179,9 @@ namespace Microsoft.DotNet.Cli.Utils
if (commandSpec == null) if (commandSpec == null)
{ {
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: commandSpec is null."); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.CommandSpecIsNull,
ProjectToolsCommandResolverName));
} }
commandSpec?.AddEnvironmentVariablesFromProject(project); commandSpec?.AddEnvironmentVariablesFromProject(project);
@ -212,7 +237,10 @@ namespace Microsoft.DotNet.Cli.Utils
depsPathRoot, depsPathRoot,
toolLibrary.Name + FileNameSuffixes.DepsJson); toolLibrary.Name + FileNameSuffixes.DepsJson);
Reporter.Verbose.WriteLine($"projecttoolscommandresolver: expect deps.json at: {depsJsonPath}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.ExpectDepsJsonAt,
ProjectToolsCommandResolverName,
depsJsonPath));
EnsureToolJsonDepsFileExists(toolLockFile, depsJsonPath, toolLibrary); EnsureToolJsonDepsFileExists(toolLockFile, depsJsonPath, toolLibrary);
@ -235,7 +263,9 @@ namespace Microsoft.DotNet.Cli.Utils
string depsPath, string depsPath,
SingleProjectInfo toolLibrary) SingleProjectInfo toolLibrary)
{ {
Reporter.Verbose.WriteLine($"Generating deps.json at: {depsPath}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.GeneratingDepsJson,
depsPath));
var dependencyContext = new DepsJsonBuilder() var dependencyContext = new DepsJsonBuilder()
.Build(toolLibrary, null, toolLockFile, s_toolPackageFramework, null); .Build(toolLibrary, null, toolLockFile, s_toolPackageFramework, null);
@ -254,7 +284,9 @@ namespace Microsoft.DotNet.Cli.Utils
} }
catch (Exception e) catch (Exception e)
{ {
Reporter.Verbose.WriteLine($"unable to generate deps.json, it may have been already generated: {e.Message}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.UnableToGenerateDepsJson,
e.Message));
try try
{ {
@ -262,7 +294,9 @@ namespace Microsoft.DotNet.Cli.Utils
} }
catch (Exception e2) catch (Exception e2)
{ {
Reporter.Verbose.WriteLine($"unable to delete temporary deps.json file: {e2.Message}"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.UnableToDeleteTemporaryDepsJson,
e2.Message));
} }
} }
} }

View file

@ -59,7 +59,7 @@ namespace Microsoft.DotNet.Cli.Utils
var host = muxer.MuxerPath; var host = muxer.MuxerPath;
if (host == null) if (host == null)
{ {
throw new Exception("Unable to locate dotnet multiplexer"); throw new Exception(LocalizableStrings.UnableToLocateDotnetMultiplexer);
} }
arguments.Add("exec"); arguments.Add("exec");

View file

@ -7,6 +7,8 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
public class PublishedPathCommandResolver : ICommandResolver public class PublishedPathCommandResolver : ICommandResolver
{ {
private const string PublishedPathCommandResolverName = "PublishedPathCommandResolver";
private readonly IEnvironmentProvider _environment; private readonly IEnvironmentProvider _environment;
private readonly IPublishedPathCommandSpecFactory _commandSpecFactory; private readonly IPublishedPathCommandSpecFactory _commandSpecFactory;
@ -39,14 +41,20 @@ namespace Microsoft.DotNet.Cli.Utils
var depsFilePath = Path.Combine(publishDirectory, $"{applicationName}.deps.json"); var depsFilePath = Path.Combine(publishDirectory, $"{applicationName}.deps.json");
if (!File.Exists(depsFilePath)) if (!File.Exists(depsFilePath))
{ {
Reporter.Verbose.WriteLine($"PublishedPathCommandResolver: {depsFilePath} does not exist"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.DoesNotExist,
PublishedPathCommandResolverName,
depsFilePath));
return null; return null;
} }
var runtimeConfigPath = Path.Combine(publishDirectory, $"{applicationName}.runtimeconfig.json"); var runtimeConfigPath = Path.Combine(publishDirectory, $"{applicationName}.runtimeconfig.json");
if (!File.Exists(runtimeConfigPath)) if (!File.Exists(runtimeConfigPath))
{ {
Reporter.Verbose.WriteLine($"projectdependenciescommandresolver: {runtimeConfigPath} does not exist"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.DoesNotExist,
PublishedPathCommandResolverName,
runtimeConfigPath));
return null; return null;
} }
@ -62,7 +70,10 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
if (!Directory.Exists(publishDirectory)) if (!Directory.Exists(publishDirectory))
{ {
Reporter.Verbose.WriteLine($"publishedpathresolver: {publishDirectory} does not exist"); Reporter.Verbose.WriteLine(string.Format(
LocalizableStrings.DoesNotExist,
PublishedPathCommandResolverName,
publishDirectory));
return null; return null;
} }

View file

@ -35,7 +35,9 @@ namespace Microsoft.DotNet.Cli.Utils
var bestVersion = versionRange.FindBestMatch(availableToolVersions); var bestVersion = versionRange.FindBestMatch(availableToolVersions);
if (bestVersion == null) if (bestVersion == null)
{ {
throw new GracefulException($"Version for package `{packageId}` could not be resolved."); throw new GracefulException(string.Format(
LocalizableStrings.VersionForPackageCouldNotBeResolved,
packageId));
} }
return GetLockFilePath(packageId, bestVersion, framework); return GetLockFilePath(packageId, bestVersion, framework);

View file

@ -8,11 +8,17 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
} }
public CommandUnknownException(string commandName) : base($"No executable found matching command \"{commandName}\"") public CommandUnknownException(string commandName) : base(string.Format(
LocalizableStrings.NoExecutableFoundMatchingCommand,
commandName))
{ {
} }
public CommandUnknownException(string commandName, Exception innerException) : base($"No executable found matching command \"{commandName}\"", innerException) public CommandUnknownException(string commandName, Exception innerException) : base(
string.Format(
LocalizableStrings.NoExecutableFoundMatchingCommand,
commandName),
innerException)
{ {
} }
} }

View file

@ -21,8 +21,8 @@ namespace Microsoft.DotNet.Cli.Utils
public static void WaitForDebugger() public static void WaitForDebugger()
{ {
Console.WriteLine("Waiting for debugger to attach. Press ENTER to continue"); Console.WriteLine(LocalizableStrings.WaitingForDebuggerToAttach);
Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}"); Console.WriteLine(string.Format(LocalizableStrings.ProcessId, Process.GetCurrentProcess().Id));
Console.ReadLine(); Console.ReadLine();
} }
} }

View file

@ -24,8 +24,8 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
throw new GracefulException(string.Join( throw new GracefulException(string.Join(
Environment.NewLine, Environment.NewLine,
$"File not found `{path}`.", string.Format(LocalizableStrings.FileNotFound, path),
"The project may not have been restored or restore failed - run `dotnet restore`")); LocalizableStrings.ProjectNotRestoredOrRestoreFailed));
} }
return await ConcurrencyUtilities.ExecuteWithFileLockedAsync( return await ConcurrencyUtilities.ExecuteWithFileLockedAsync(

View file

@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
if (attemptsLeft < 1) if (attemptsLeft < 1)
{ {
throw new InvalidOperationException("Could not access assets file."); throw new InvalidOperationException(LocalizableStrings.CouldNotAccessAssetsFile);
} }
attemptsLeft--; attemptsLeft--;

View file

@ -0,0 +1,89 @@
namespace Microsoft.DotNet.Cli.Utils
{
internal class LocalizableStrings
{
public const string MalformedText = "Malformed command text '{0}'";
public const string BuildOutputPathDoesNotExist = "outputpathresolver: {0} does not exist";
public const string AttemptingToFindCommand = "{0}: attempting to find command {1} in {2}";
public const string FailedToFindToolAssembly = "{0}: failed to find toolAssembly for {1}";
public const string FailedToFindCommandPath = "{0}: failed to find commandPath {1}";
public const string UnableToLocateDotnetMultiplexer = "Unable to locate dotnet multiplexer";
public const string LookingForPreferCliRuntimeFile = "{0}: Looking for prefercliruntime file at `{1}`";
public const string AttemptingToResolve = "{0}: attempting to resolve {1}";
public const string DidNotFindAMatchingProject = "{0}: Did not find a matching project {1}.";
public const string InvalidCommandResolverArguments = "{0}: invalid commandResolverArguments";
public const string DoesNotExist = "{0}: {1} does not exist";
public const string AmbiguousCommandName = "Ambiguous command name: {0}";
public const string ToolLibraryFound = "{0}: tool library found {1}";
public const string MSBuildExePath = "{0}: MSBUILD_EXE_PATH = {1}";
public const string MSBuildProjectPath = "{0}: MSBuild project path = {1}";
public const string MultipleProjectFilesFound = "Specify which project file to use because this '{0}' contains more than one project file.";
public const string DidNotFindProject = "{0}: ProjectFactory did not find Project.";
public const string ResolvingCommandSpec = "{0}: resolving commandspec from {1} Tool Libraries.";
public const string FailedToResolveCommandSpec = "{0}: failed to resolve commandspec from library.";
public const string AttemptingToResolveCommandSpec = "{0}: Attempting to resolve command spec from tool {1}";
public const string NuGetPackagesRoot = "{0}: nuget packages root:\n{1}";
public const string FoundToolLockFile = "{0}: found tool lockfile at : {1}";
public const string LibraryNotFoundInLockFile = "{0}: library not found in lock file.";
public const string AttemptingToCreateCommandSpec = "{0}: attempting to create commandspec";
public const string CommandSpecIsNull = "{0}: commandSpec is null.";
public const string ExpectDepsJsonAt = "{0}: expect deps.json at: {1}";
public const string GeneratingDepsJson = "Generating deps.json at: {0}";
public const string UnableToGenerateDepsJson = "unable to generate deps.json, it may have been already generated: {0}";
public const string UnableToDeleteTemporaryDepsJson = "unable to delete temporary deps.json file: {0}";
public const string VersionForPackageCouldNotBeResolved = "Version for package `{0}` could not be resolved.";
public const string FileNotFound = "File not found `{0}`.";
public const string ProjectNotRestoredOrRestoreFailed = "The project may not have been restored or restore failed - run `dotnet restore`";
public const string NoExecutableFoundMatchingCommand = "No executable found matching command \"{0}\"";
public const string WaitingForDebuggerToAttach = "Waiting for debugger to attach. Press ENTER to continue";
public const string ProcessId = "Process ID: {0}";
public const string CouldNotAccessAssetsFile = "Could not access assets file.";
public const string DotNetCommandLineTools = ".NET Command Line Tools";
public const string WriteLineForwarderSetPreviously = "WriteLine forwarder set previously";
public const string AlreadyCapturingStream = "Already capturing stream!";
public const string RunningFileNameArguments = "Running {0} {1}";
public const string ProcessExitedWithCode = "< {0} exited with {1} in {2} ms.";
public const string UnableToInvokeMemberNameAfterCommand = "Unable to invoke {0} after the command has been run";
}
}

View file

@ -26,7 +26,7 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
if (_muxerPath == null) if (_muxerPath == null)
{ {
throw new InvalidOperationException("Unable to locate dotnet multiplexer"); throw new InvalidOperationException(LocalizableStrings.UnableToLocateDotnetMultiplexer);
} }
return _muxerPath; return _muxerPath;
} }

View file

@ -4,12 +4,15 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
public class Product public class Product
{ {
public static readonly string LongName = ".NET Command Line Tools"; public static readonly string LongName = LocalizableStrings.DotNetCommandLineTools;
public static readonly string Version = GetProductVersion(); public static readonly string Version = GetProductVersion();
private static string GetProductVersion() private static string GetProductVersion()
{ {
var attr = typeof(Product).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>(); var attr = typeof(Product)
.GetTypeInfo()
.Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
return attr?.InformationalVersion; return attr?.InformationalVersion;
} }
} }

View file

@ -118,7 +118,7 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
if (_writeLine != null) if (_writeLine != null)
{ {
throw new InvalidOperationException("WriteLine forwarder set previously"); throw new InvalidOperationException(LocalizableStrings.WriteLineForwarderSetPreviously);
} }
} }
@ -126,7 +126,7 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
if (_capture != null) if (_capture != null)
{ {
throw new InvalidOperationException("Already capturing stream!"); throw new InvalidOperationException(LocalizableStrings.AlreadyCapturingStream);
} }
} }
} }

View file

@ -35,19 +35,7 @@ namespace Microsoft.DotNet.Configurer
private void PrintFirstTimeUseNotice() private void PrintFirstTimeUseNotice()
{ {
const string firstTimeUseWelcomeMessage = @"Welcome to .NET Core! const string firstTimeUseWelcomeMessage = LocalizableStrings.FirstTimeWelcomeMessage;
---------------------
Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
Telemetry
--------------
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
Configuring...
-------------------
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.";
Reporter.Output.WriteLine(); Reporter.Output.WriteLine();
Reporter.Output.WriteLine(firstTimeUseWelcomeMessage); Reporter.Output.WriteLine(firstTimeUseWelcomeMessage);

View file

@ -0,0 +1,24 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.DotNet.Configurer
{
internal class LocalizableStrings
{
public const string FirstTimeWelcomeMessage = @"Welcome to .NET Core!
---------------------
Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
Telemetry
--------------
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include command-line arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
Configuring...
-------------------
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.";
public const string FailedToPrimeCacheError = "Failed to create prime the NuGet cache. {0} failed with: {1}";
}
}

View file

@ -116,7 +116,7 @@ namespace Microsoft.DotNet.Configurer
Reporter.Verbose.WriteLine(commandResult.StdErr); Reporter.Verbose.WriteLine(commandResult.StdErr);
Reporter.Error.WriteLine( Reporter.Error.WriteLine(
$"Failed to create prime the NuGet cache. {commandToExecute} failed with: {commandResult.ExitCode}"); string.Format(LocalizableStrings.FailedToPrimeCacheError, commandToExecute, commandResult.ExitCode));
} }
return commandResult.ExitCode == 0; return commandResult.ExitCode == 0;

View file

@ -33,7 +33,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
{ {
foreach (var rule in Rules) foreach (var rule in Rules)
{ {
MigrationTrace.Instance.WriteLine($"{nameof(DefaultMigrationRuleSet)}: Executing migration rule {rule.GetType().Name}"); MigrationTrace.Instance.WriteLine(string.Format(LocalizableStrings.ExecutingMigrationRule, nameof(DefaultMigrationRuleSet), rule.GetType().Name));
rule.Apply(migrationSettings, migrationRuleInputs); rule.Apply(migrationSettings, migrationRuleInputs);
} }
} }

View file

@ -0,0 +1,126 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.DotNet.ProjectJsonMigration
{
public class LocalizableStrings
{
public const string DoubleMigrationError = "Detected double project migration: {0}";
public const string CannotMergeMetadataError = "Cannot merge metadata with the same name and different values";
public const string NoXprojFileGivenError = "{0}: No xproj file given.";
public const string MultipleXprojFilesError = "Multiple xproj files found in {0}, please specify which to use";
public const string NullMSBuildProjectTemplateError = "Expected non-null MSBuildProjectTemplate in MigrationSettings";
public const string CannotMigrateProjectWithCompilerError = "Cannot migrate project {0} using compiler {1}";
public const string ExpectedElementToBeOfTypeNotTypeError = "Expected element to be of type {0}, but got {1}";
public const string ProjAlreadyExistsError = "{0} already exists. Has migration already been run?";
public const string NullDestinationElementError = "expected destinationElement to not be null";
public const string DiagnosticMessageTemplate = "{0} (line: {1}, file: {2})";
public const string CannotMergeItemsOfDifferentTypesError = "Cannot merge items of different types.";
public const string CannotMergeItemsWithoutCommonIncludeError = "Cannot merge items without a common include.";
public const string PropertyTransformApplicatorWrongElementTypeError = "Expected element to be of type {0}, but got {1}";
public const string UnexpectedTypeError = "Unexpected type {0}";
public const string MIGRATE1011 = "Deprecated Project";
public const string MIGRATE1012 = "Project not Restored";
public const string MIGRATE1013 = "No Project";
public const string MIGRATE1013Arg = "The project.json specifies no target frameworks in {0}";
public const string MIGRATE1014 = "Unresolved Dependency";
public const string MIGRATE1014Arg = "Unresolved project dependency ({0})";
public const string MIGRATE1015 = "File Overwrite";
public const string MIGRATE1016 = "Unsupported Script Variable";
public const string MIGRATE1016Arg = "{0} is currently an unsupported script variable for project migration";
public const string MIGRATE1017 = "Multiple Xproj Files";
public const string MIGRATE1018 = "Dependency Project not found";
public const string MIGRATE1018Arg = "Dependency project not found ({0})" ;
public const string MIGRATE1019 = "Unsupported Script Event Hook";
public const string MIGRATE1019Arg = "{0} is an unsupported script event hook for project migration";
public const string MIGRATE20011 = "Multi-TFM";
public const string MIGRATE20012 = "Configuration Exclude";
public const string MIGRATE20013 = "Non-Csharp App";
public const string MIGRATE20018 = "Files specified under PackOptions";
public const string IncludesNotEquivalent = "{0}.{1} includes not equivalent.";
public const string ExcludesNotEquivalent = "{0}.{1} excludes not equivalent.";
public const string RemovesNotEquivalent = "{0}.{1} removes not equivalent.";
public const string MetadataDoesntExist = "{0}.{1} metadata doesn't exist {{ {2} {3} }}";
public const string MetadataHasAnotherValue = "{0}.{1} metadata has another value {{ {2} {3} {4} }}";
public const string AddingMetadataToItem = "{0}: Adding metadata to {1} item: {{ {2}, {3}, {4} }}";
public const string SkipMigrationAlreadyMigrated = "{0}: Skip migrating {1}, it is already migrated.";
public const string ExecutingRule = "Executing rule: {0}";
public const string NoConfigurationOrFrameworkFoundInProject = "{0}: No configuration or framework build options found in project";
public const string MigratingCountTargetFrameworks = "Migrating {0} target frameworks";
public const string MigratingFramework = "Migrating framework {0}";
public const string ImportsTransformNullFor = "{0}: imports transform null for {1}";
public const string MigratingCountXprojToCsprojReferences = "{0}: Migrating {1} xproj to csproj references";
public const string ExecutingMigrationRule = "{0}: Executing migration rule {1}";
public const string ItemTransformApplicatorHeader = "{0}: Item {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4}, Update: {5} }}";
public const string ItemTransformApplicatorItemGroup = "{0}: ItemGroup {{ Condition: {1} }}";
public const string ItemTransformAppliatorItemCompletelyMerged = "{0}: Item completely merged";
public const string ItemTransformApplicatorAddItemHeader = "{0}: AddItemToItemGroup {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4}, Update: {5} }}";
public const string ItemTransformApplicatorMergingItemWithExistingItems = "{0}: Merging Item with {1} existing items with a different condition chain.";
public const string ItemTransformApplicatorEncompassedIncludes = "{0}: encompassed includes {1}";
public const string ItemTransformApplicatorRemovingItem = "{0}: Removing Item {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4} }}";
public const string ItemTransformApplicatorIgnoringItem = "{0}: Ignoring Item {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4} }}";
public const string ItemTransformApplicatorMergingItemWithExistingItemsSameChain = "{0}: Merging Item with {1} existing items with the same condition chain.";
public const string ItemTransformApplicatorAddingMergedItem = "{0}: Adding Merged Item {{ ItemType: {1}, Condition: {2}, Include: {3}, Exclude: {4} }}";
public const string MergingProperty = "Merging property, output merged property";
public const string IgnoringMergedProperty = "Ignoring fully merged property";
public const string PropertyInfo = "{0}: {1}, {{ Name={2}, Value={3} }}";
}
}

View file

@ -28,7 +28,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (item.IntersectIncludes(otherItem).Count() != item.Includes().Count()) if (item.IntersectIncludes(otherItem).Count() != item.Includes().Count())
{ {
#if !DISABLE_TRACE #if !DISABLE_TRACE
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} includes not equivalent."); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.IncludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
#endif #endif
return false; return false;
} }
@ -37,7 +37,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (item.IntersectExcludes(otherItem).Count() != item.Excludes().Count()) if (item.IntersectExcludes(otherItem).Count() != item.Excludes().Count())
{ {
#if !DISABLE_TRACE #if !DISABLE_TRACE
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} excludes not equivalent."); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ExcludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
#endif #endif
return false; return false;
} }
@ -51,7 +51,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (item.Remove != otherItem.Remove) if (item.Remove != otherItem.Remove)
{ {
#if !DISABLE_TRACE #if !DISABLE_TRACE
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} removes not equivalent."); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.RemovesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
#endif #endif
return false; return false;
} }
@ -68,7 +68,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (otherMetadata == null) if (otherMetadata == null)
{ {
#if !DISABLE_TRACE #if !DISABLE_TRACE
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} metadata doesn't exist {{ {metadata.Name} {metadata.Value} }}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MetadataDoesntExist, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value));
#endif #endif
return false; return false;
} }
@ -76,7 +76,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (!metadata.ValueEquals(otherMetadata)) if (!metadata.ValueEquals(otherMetadata))
{ {
#if !DISABLE_TRACE #if !DISABLE_TRACE
MigrationTrace.Instance.WriteLine($"{nameof(MSBuildExtensions)}.{nameof(IsEquivalentTo)} metadata has another value {{ {metadata.Name} {metadata.Value} {otherMetadata.Value} }}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MetadataHasAnotherValue, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value, otherMetadata.Value));
#endif #endif
return false; return false;
} }
@ -202,13 +202,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (existingMetadata != default(ProjectMetadataElement) && !existingMetadata.ValueEquals(metadata)) if (existingMetadata != default(ProjectMetadataElement) && !existingMetadata.ValueEquals(metadata))
{ {
throw new Exception("Cannot merge metadata with the same name and different values"); throw new Exception(LocalizableStrings.CannotMergeMetadataError);
} }
if (existingMetadata == default(ProjectMetadataElement)) if (existingMetadata == default(ProjectMetadataElement))
{ {
#if !DISABLE_TRACE #if !DISABLE_TRACE
MigrationTrace.Instance.WriteLine($"{nameof(AddMetadata)}: Adding metadata to {item.ItemType} item: {{ {metadata.Name}, {metadata.Value}, {metadata.Condition} }}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.AddingMetadataToItem, nameof(AddMetadata), item.ItemType, metadata.Name, metadata.Value, metadata.Condition));
#endif #endif
var metametadata = item.AddMetadata(metadata.Name, metadata.Value); var metametadata = item.AddMetadata(metadata.Name, metadata.Value);
metametadata.Condition = metadata.Condition; metametadata.Condition = metadata.Condition;

View file

@ -8,43 +8,43 @@ namespace Microsoft.DotNet.ProjectJsonMigration
internal static partial class MigrationErrorCodes internal static partial class MigrationErrorCodes
{ {
public static Func<string, MigrationError> MIGRATE1011 public static Func<string, MigrationError> MIGRATE1011
=> (message) => new MigrationError(nameof(MIGRATE1011), "Deprecated Project", message); => (message) => new MigrationError(nameof(MIGRATE1011), LocalizableStrings.MIGRATE1011, message);
public static Func<string, MigrationError> MIGRATE1012 public static Func<string, MigrationError> MIGRATE1012
=> (message) => new MigrationError(nameof(MIGRATE1012), "Project not Restored", message); => (message) => new MigrationError(nameof(MIGRATE1012), LocalizableStrings.MIGRATE1012, message);
public static Func<string, MigrationError> MIGRATE1013 public static Func<string, MigrationError> MIGRATE1013
=> (message) => new MigrationError(nameof(MIGRATE1013), "No Project", message); => (message) => new MigrationError(nameof(MIGRATE1013), LocalizableStrings.MIGRATE1013, message);
public static Func<string, MigrationError> MIGRATE1014 public static Func<string, MigrationError> MIGRATE1014
=> (message) => new MigrationError(nameof(MIGRATE1014), "Unresolved Dependency", message); => (message) => new MigrationError(nameof(MIGRATE1014), LocalizableStrings.MIGRATE1014, message);
public static Func<string, MigrationError> MIGRATE1015 public static Func<string, MigrationError> MIGRATE1015
=> (message) => new MigrationError(nameof(MIGRATE1015), "File Overwrite", message); => (message) => new MigrationError(nameof(MIGRATE1015), LocalizableStrings.MIGRATE1015, message);
public static Func<string, MigrationError> MIGRATE1016 public static Func<string, MigrationError> MIGRATE1016
=> (message) => new MigrationError(nameof(MIGRATE1016), "Unsupported Script Variable", message); => (message) => new MigrationError(nameof(MIGRATE1016), LocalizableStrings.MIGRATE1016, message);
public static Func<string, MigrationError> MIGRATE1017 public static Func<string, MigrationError> MIGRATE1017
=> (message) => new MigrationError(nameof(MIGRATE1017), "Multiple Xproj Files", message); => (message) => new MigrationError(nameof(MIGRATE1017), LocalizableStrings.MIGRATE1017, message);
public static Func<string, MigrationError> MIGRATE1018 public static Func<string, MigrationError> MIGRATE1018
=> (message) => new MigrationError(nameof(MIGRATE1018), "Dependency Project not found", message); => (message) => new MigrationError(nameof(MIGRATE1018), LocalizableStrings.MIGRATE1018, message);
public static Func<string, MigrationError> MIGRATE1019 public static Func<string, MigrationError> MIGRATE1019
=> (message) => new MigrationError(nameof(MIGRATE1019), "Unsupported Script Event Hook", message); => (message) => new MigrationError(nameof(MIGRATE1019), LocalizableStrings.MIGRATE1019, message);
// Potentially Temporary (Point in Time) Errors // Potentially Temporary (Point in Time) Errors
public static Func<string, MigrationError> MIGRATE20011 public static Func<string, MigrationError> MIGRATE20011
=> (message) => new MigrationError(nameof(MIGRATE20011), "Multi-TFM", message); => (message) => new MigrationError(nameof(MIGRATE20011), LocalizableStrings.MIGRATE20011, message);
public static Func<string, MigrationError> MIGRATE20012 public static Func<string, MigrationError> MIGRATE20012
=> (message) => new MigrationError(nameof(MIGRATE20012), "Configuration Exclude", message); => (message) => new MigrationError(nameof(MIGRATE20012), LocalizableStrings.MIGRATE20012, message);
public static Func<string, MigrationError> MIGRATE20013 public static Func<string, MigrationError> MIGRATE20013
=> (message) => new MigrationError(nameof(MIGRATE20013), "Non-Csharp App", message); => (message) => new MigrationError(nameof(MIGRATE20013), LocalizableStrings.MIGRATE20013, message);
public static Func<string, MigrationError> MIGRATE20018 public static Func<string, MigrationError> MIGRATE20018
=> (message) => new MigrationError(nameof(MIGRATE20018), "Files specified under PackOptions", message); => (message) => new MigrationError(nameof(MIGRATE20018), LocalizableStrings.MIGRATE20018, message);
} }
} }

View file

@ -66,7 +66,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (!File.Exists(project.ProjectFilePath)) if (!File.Exists(project.ProjectFilePath))
{ {
MigrationErrorCodes MigrationErrorCodes
.MIGRATE1018($"Dependency project not found ({project.ProjectFilePath})").Throw(); .MIGRATE1018(String.Format(LocalizableStrings.MIGRATE1018Arg, project.ProjectFilePath)).Throw();
} }
var projectContext = var projectContext =
@ -140,7 +140,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (projectFileDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project) if (projectFileDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project)
{ {
MigrationErrorCodes MigrationErrorCodes
.MIGRATE1014($"Unresolved project dependency ({dependencyName})").Throw(); .MIGRATE1014(String.Format(LocalizableStrings.MIGRATE1014Arg, dependencyName)).Throw();
} }
else else
{ {
@ -158,7 +158,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
{ {
if (xproj == null) if (xproj == null)
{ {
MigrationTrace.Instance.WriteLine($"{nameof(ProjectDependencyFinder)}: No xproj file given."); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.NoXprojFileGivenError, nameof(ProjectDependencyFinder)));
return Enumerable.Empty<ProjectItemElement>(); return Enumerable.Empty<ProjectItemElement>();
} }
@ -175,7 +175,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (allXprojFiles.Count() > 1) if (allXprojFiles.Count() > 1)
{ {
MigrationErrorCodes MigrationErrorCodes
.MIGRATE1017($"Multiple xproj files found in {projectDirectory}, please specify which to use") .MIGRATE1017(String.Format(LocalizableStrings.MultipleXprojFilesError, projectDirectory))
.Throw(); .Throw();
} }
@ -210,7 +210,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (projectExport.Library.Identity.Type.Equals(LibraryType.Project)) if (projectExport.Library.Identity.Type.Equals(LibraryType.Project))
{ {
MigrationErrorCodes MigrationErrorCodes
.MIGRATE1014($"Unresolved project dependency ({projectExportName})").Throw(); .MIGRATE1014(String.Format(LocalizableStrings.MIGRATE1014Arg, projectExportName)).Throw();
} }
else else
{ {

View file

@ -137,7 +137,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
{ {
if (IsMigrated(migrationSettings, migrationRuleInputs)) if (IsMigrated(migrationSettings, migrationRuleInputs))
{ {
MigrationTrace.Instance.WriteLine($"{nameof(ProjectMigrator)}: Skip migrating {migrationSettings.ProjectDirectory}, it is already migrated."); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.SkipMigrationAlreadyMigrated, nameof(ProjectMigrator), migrationSettings.ProjectDirectory));
return new ProjectMigrationReport(migrationSettings.ProjectDirectory, projectName, skipped: true); return new ProjectMigrationReport(migrationSettings.ProjectDirectory, projectName, skipped: true);
} }
@ -175,7 +175,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
var templateMSBuildProject = migrationSettings.MSBuildProjectTemplate; var templateMSBuildProject = migrationSettings.MSBuildProjectTemplate;
if (templateMSBuildProject == null) if (templateMSBuildProject == null)
{ {
throw new Exception("Expected non-null MSBuildProjectTemplate in MigrationSettings"); throw new Exception(LocalizableStrings.NullMSBuildProjectTemplateError);
} }
var propertyGroup = templateMSBuildProject.AddPropertyGroup(); var propertyGroup = templateMSBuildProject.AddPropertyGroup();
@ -193,7 +193,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
{ {
if (!projectContexts.Any()) if (!projectContexts.Any())
{ {
MigrationErrorCodes.MIGRATE1013($"The project.json specifies no target frameworks in {projectDirectory}").Throw(); MigrationErrorCodes.MIGRATE1013(String.Format(LocalizableStrings.MIGRATE1013Arg, projectDirectory)).Throw();
} }
var defaultProjectContext = projectContexts.First(); var defaultProjectContext = projectContexts.First();
@ -202,7 +202,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (diagnostics.Any()) if (diagnostics.Any())
{ {
MigrationErrorCodes.MIGRATE1011( MigrationErrorCodes.MIGRATE1011(
$"{projectDirectory}{Environment.NewLine}{string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d)))}") String.Format("{0}{1}{2}", projectDirectory, Environment.NewLine, string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d)))))
.Throw(); .Throw();
} }
@ -212,13 +212,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (!compilerName.Equals("csc", StringComparison.OrdinalIgnoreCase)) if (!compilerName.Equals("csc", StringComparison.OrdinalIgnoreCase))
{ {
MigrationErrorCodes.MIGRATE20013( MigrationErrorCodes.MIGRATE20013(
$"Cannot migrate project {defaultProjectContext.ProjectFile.ProjectFilePath} using compiler {compilerName}").Throw(); String.Format(LocalizableStrings.CannotMigrateProjectWithCompilerError, defaultProjectContext.ProjectFile.ProjectFilePath, compilerName)).Throw();
} }
} }
private string FormatDiagnosticMessage(DiagnosticMessage d) private string FormatDiagnosticMessage(DiagnosticMessage d)
{ {
return $"{d.Message} (line: {d.StartLine}, file: {d.SourceFilePath})"; return String.Format(LocalizableStrings.DiagnosticMessageTemplate, d.Message, d.StartLine, d.SourceFilePath);
} }
private void SetupOutputDirectory(string projectDirectory, string outputDirectory) private void SetupOutputDirectory(string projectDirectory, string outputDirectory)

View file

@ -45,7 +45,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
} }
else if (!report.Skipped) else if (!report.Skipped)
{ {
MigrationTrace.Instance.WriteLine("Detected double project migration: {report.ProjectDirectory}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.DoubleMigrationError, report.ProjectDirectory));
} }
} }
else else

View file

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Build.Construction; using Microsoft.Build.Construction;
@ -13,7 +14,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
{ {
public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs) public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
{ {
MigrationTrace.Instance.WriteLine($"Executing rule: {nameof(MigrateConfigurationsRule)}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ExecutingRule, nameof(MigrateConfigurationsRule)));
var projectContext = migrationRuleInputs.DefaultProjectContext; var projectContext = migrationRuleInputs.DefaultProjectContext;
var configurations = projectContext.ProjectFile.GetConfigurations().ToList(); var configurations = projectContext.ProjectFile.GetConfigurations().ToList();
@ -22,7 +23,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
if (!configurations.Any() && !frameworks.Any()) if (!configurations.Any() && !frameworks.Any())
{ {
MigrationTrace.Instance.WriteLine($"{nameof(MigrateConfigurationsRule)}: No configuration or framework build options found in project"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.NoConfigurationOrFrameworkFoundInProject, nameof(MigrateConfigurationsRule)));
return; return;
} }

View file

@ -55,10 +55,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
migrationSettings.SolutionFile, migrationSettings.SolutionFile,
itemGroup: noFrameworkPackageReferenceItemGroup); itemGroup: noFrameworkPackageReferenceItemGroup);
MigrationTrace.Instance.WriteLine($"Migrating {targetFrameworks.Count()} target frameworks"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MigratingCountTargetFrameworks, targetFrameworks.Count()));
foreach (var targetFramework in targetFrameworks) foreach (var targetFramework in targetFrameworks)
{ {
MigrationTrace.Instance.WriteLine($"Migrating framework {targetFramework.FrameworkName.GetShortFolderName()}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MigratingFramework, targetFramework.FrameworkName.GetShortFolderName()));
MigrateImports(migrationRuleInputs.CommonPropertyGroup, targetFramework); MigrateImports(migrationRuleInputs.CommonPropertyGroup, targetFramework);
@ -172,7 +172,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
} }
else else
{ {
MigrationTrace.Instance.WriteLine($"{nameof(MigratePackageDependenciesAndToolsRule)}: imports transform null for {targetFramework.FrameworkName.GetShortFolderName()}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ImportsTransformNullFor, nameof(MigratePackageDependenciesAndToolsRule), targetFramework.FrameworkName.GetShortFolderName()));
} }
} }

View file

@ -68,7 +68,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
csprojTransformedReferences.Add(transformItem); csprojTransformedReferences.Add(transformItem);
} }
MigrationTrace.Instance.WriteLine($"{nameof(MigrateProjectDependenciesRule)}: Migrating {csprojTransformedReferences.Count()} xproj to csproj references"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MigratingCountXprojToCsprojReferences, nameof(MigrateProjectDependenciesRule), csprojTransformedReferences.Count()));
foreach (var csprojTransformedReference in csprojTransformedReferences) foreach (var csprojTransformedReference in csprojTransformedReferences)
{ {

View file

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO; using System.IO;
namespace Microsoft.DotNet.ProjectJsonMigration.Rules namespace Microsoft.DotNet.ProjectJsonMigration.Rules
@ -20,7 +21,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
if (File.Exists(outputRuntimeOptionsFile)) if (File.Exists(outputRuntimeOptionsFile))
{ {
MigrationErrorCodes.MIGRATE1015( MigrationErrorCodes.MIGRATE1015(
$"{outputRuntimeOptionsFile} already exists. Has migration already been run?").Throw(); String.Format(LocalizableStrings.ProjAlreadyExistsError, outputRuntimeOptionsFile)).Throw();
} }
File.WriteAllText(outputRuntimeOptionsFile, raw); File.WriteAllText(outputRuntimeOptionsFile, raw);

View file

@ -65,7 +65,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
if (ScriptVariableToMSBuildMap[key] == null) if (ScriptVariableToMSBuildMap[key] == null)
{ {
MigrationErrorCodes.MIGRATE1016( MigrationErrorCodes.MIGRATE1016(
$"{key} is currently an unsupported script variable for project migration") String.Format(LocalizableStrings.MIGRATE1016Arg, key))
.Throw(); .Throw();
} }
@ -102,7 +102,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
if(!ScriptSetToMSBuildHookTargetMap.TryGetValue(scriptSetName, out targetHookInfo)) if(!ScriptSetToMSBuildHookTargetMap.TryGetValue(scriptSetName, out targetHookInfo))
{ {
MigrationErrorCodes.MIGRATE1019( MigrationErrorCodes.MIGRATE1019(
$"{scriptSetName} is an unsupported script event hook for project migration") String.Format(LocalizableStrings.MIGRATE1019Arg, scriptSetName))
.Throw(); .Throw();
} }

View file

@ -19,12 +19,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{ {
if (typeof(T) != typeof(ProjectItemElement)) if (typeof(T) != typeof(ProjectItemElement))
{ {
throw new ArgumentException($"Expected element to be of type {nameof(ProjectItemElement)}, but got {typeof(T)}"); throw new ArgumentException(String.Format(LocalizableStrings.ExpectedElementToBeOfTypeNotTypeError, nameof(ProjectItemElement), typeof(T)));
} }
if (typeof(U) != typeof(ProjectItemGroupElement)) if (typeof(U) != typeof(ProjectItemGroupElement))
{ {
throw new ArgumentException($"Expected destinationElement to be of type {nameof(ProjectItemGroupElement)}, but got {typeof(U)}"); throw new ArgumentException(String.Format(LocalizableStrings.ExpectedElementToBeOfTypeNotTypeError, nameof(ProjectItemGroupElement), typeof(U)));
} }
if (element == null) if (element == null)
@ -34,14 +34,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
if (destinationElement == null) if (destinationElement == null)
{ {
throw new ArgumentException("expected destinationElement to not be null"); throw new ArgumentException(LocalizableStrings.NullDestinationElementError);
} }
var item = element as ProjectItemElement; var item = element as ProjectItemElement;
var destinationItemGroup = destinationElement as ProjectItemGroupElement; var destinationItemGroup = destinationElement as ProjectItemGroupElement;
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Item {{ ItemType: {item.ItemType}, Condition: {item.Condition}, Include: {item.Include}, Exclude: {item.Exclude}, Update: {item.Update} }}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorHeader, nameof(ItemTransformApplicator), item.ItemType, item.Condition, item.Include, item.Exclude, item.Update));
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: ItemGroup {{ Condition: {destinationItemGroup.Condition} }}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorItemGroup, nameof(ItemTransformApplicator), destinationItemGroup.Condition));
if (mergeExisting) if (mergeExisting)
{ {
@ -49,7 +49,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
item = MergeWithExistingItemsWithSameCondition(item, destinationItemGroup); item = MergeWithExistingItemsWithSameCondition(item, destinationItemGroup);
if (item == null) if (item == null)
{ {
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Item completely merged"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformAppliatorItemCompletelyMerged, nameof(ItemTransformApplicator)));
return; return;
} }
@ -57,14 +57,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
item = MergeWithExistingItemsWithNoCondition(item, destinationItemGroup); item = MergeWithExistingItemsWithNoCondition(item, destinationItemGroup);
if (item == null) if (item == null)
{ {
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Item completely merged"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformAppliatorItemCompletelyMerged, nameof(ItemTransformApplicator)));
return; return;
} }
item = MergeWithExistingItemsWithACondition(item, destinationItemGroup); item = MergeWithExistingItemsWithACondition(item, destinationItemGroup);
if (item == null) if (item == null)
{ {
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Item completely merged"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformAppliatorItemCompletelyMerged, nameof(ItemTransformApplicator)));
return; return;
} }
} }
@ -88,7 +88,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var outputItem = itemGroup.ContainingProject.CreateItemElement("___TEMP___"); var outputItem = itemGroup.ContainingProject.CreateItemElement("___TEMP___");
outputItem.CopyFrom(item); outputItem.CopyFrom(item);
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: AddItemToItemGroup {{ ItemType: {outputItem.ItemType}, Condition: {outputItem.Condition}, Include: {outputItem.Include}, Exclude: {outputItem.Exclude}, Update: {outputItem.Update} }}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorAddItemHeader, nameof(ItemTransformApplicator), outputItem.ItemType, outputItem.Condition, outputItem.Include, outputItem.Exclude, outputItem.Update));
itemGroup.AppendChild(outputItem); itemGroup.AppendChild(outputItem);
outputItem.AddMetadata(item.Metadata); outputItem.AddMetadata(item.Metadata);
@ -105,7 +105,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var existingItemsWithACondition = var existingItemsWithACondition =
FindExistingItemsWithACondition(item, destinationItemGroup.ContainingProject, destinationItemGroup); FindExistingItemsWithACondition(item, destinationItemGroup.ContainingProject, destinationItemGroup);
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Merging Item with {existingItemsWithACondition.Count()} existing items with a different condition chain."); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorMergingItemWithExistingItems, nameof(ItemTransformApplicator), existingItemsWithACondition.Count()));
foreach (var existingItem in existingItemsWithACondition) foreach (var existingItem in existingItemsWithACondition)
{ {
@ -113,14 +113,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var encompassedIncludes = item.GetEncompassedIncludes(existingItem); var encompassedIncludes = item.GetEncompassedIncludes(existingItem);
if (encompassedIncludes.Any()) if (encompassedIncludes.Any())
{ {
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: encompassed includes {string.Join(", ", encompassedIncludes)}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorEncompassedIncludes, nameof(ItemTransformApplicator), string.Join(", ", encompassedIncludes)));
existingItem.RemoveIncludes(encompassedIncludes); existingItem.RemoveIncludes(encompassedIncludes);
} }
// continue if the existing item is now empty // continue if the existing item is now empty
if (!existingItem.Includes().Any()) if (!existingItem.Includes().Any())
{ {
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Removing Item {{ ItemType: {existingItem.ItemType}, Condition: {existingItem.Condition}, Include: {existingItem.Include}, Exclude: {existingItem.Exclude} }}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorRemovingItem, nameof(ItemTransformApplicator), existingItem.ItemType, existingItem.Condition, existingItem.Include, existingItem.Exclude));
existingItem.Parent.RemoveChild(existingItem); existingItem.Parent.RemoveChild(existingItem);
continue; continue;
} }
@ -172,7 +172,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var existingItemsWithNoCondition = var existingItemsWithNoCondition =
FindExistingItemsWithNoCondition(item, destinationItemGroup.ContainingProject, destinationItemGroup); FindExistingItemsWithNoCondition(item, destinationItemGroup.ContainingProject, destinationItemGroup);
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Merging Item with {existingItemsWithNoCondition.Count()} existing items with a different condition chain."); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorMergingItemWithExistingItems, nameof(ItemTransformApplicator), existingItemsWithNoCondition.Count()));
// Handle the item being placed inside of a condition, when it is overlapping with a conditionless item // Handle the item being placed inside of a condition, when it is overlapping with a conditionless item
// If it is not definining new metadata or excludes, the conditioned item can be merged with the // If it is not definining new metadata or excludes, the conditioned item can be merged with the
@ -182,11 +182,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var encompassedIncludes = existingItem.GetEncompassedIncludes(item); var encompassedIncludes = existingItem.GetEncompassedIncludes(item);
if (encompassedIncludes.Any()) if (encompassedIncludes.Any())
{ {
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: encompassed includes {string.Join(", ", encompassedIncludes)}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorEncompassedIncludes, nameof(ItemTransformApplicator), string.Join(", ", encompassedIncludes)));
item.RemoveIncludes(encompassedIncludes); item.RemoveIncludes(encompassedIncludes);
if (!item.Includes().Any()) if (!item.Includes().Any())
{ {
MigrationTrace.Instance.WriteLine($"{nameof(ItemTransformApplicator)}: Ignoring Item {{ ItemType: {existingItem.ItemType}, Condition: {existingItem.Condition}, Include: {existingItem.Include}, Exclude: {existingItem.Exclude} }}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorIgnoringItem, nameof(ItemTransformApplicator), existingItem.ItemType, existingItem.Condition, existingItem.Include, existingItem.Exclude));
return null; return null;
} }
} }
@ -225,7 +225,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var existingItemsWithSameCondition = var existingItemsWithSameCondition =
FindExistingItemsWithSameCondition(item, destinationItemGroup.ContainingProject, destinationItemGroup); FindExistingItemsWithSameCondition(item, destinationItemGroup.ContainingProject, destinationItemGroup);
MigrationTrace.Instance.WriteLine($"{nameof(TransformApplicator)}: Merging Item with {existingItemsWithSameCondition.Count()} existing items with the same condition chain."); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorMergingItemWithExistingItemsSameChain, nameof(TransformApplicator), existingItemsWithSameCondition.Count()));
foreach (var existingItem in existingItemsWithSameCondition) foreach (var existingItem in existingItemsWithSameCondition)
{ {
@ -238,7 +238,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
existingItem.Parent.RemoveChild(existingItem); existingItem.Parent.RemoveChild(existingItem);
} }
MigrationTrace.Instance.WriteLine($"{nameof(TransformApplicator)}: Adding Merged Item {{ ItemType: {mergeResult.MergedItem.ItemType}, Condition: {mergeResult.MergedItem.Condition}, Include: {mergeResult.MergedItem.Include}, Exclude: {mergeResult.MergedItem.Exclude} }}"); MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ItemTransformApplicatorAddingMergedItem,
nameof(TransformApplicator),
mergeResult.MergedItem.ItemType,
mergeResult.MergedItem.Condition,
mergeResult.MergedItem.Include,
mergeResult.MergedItem.Exclude));
AddItemToItemGroup(mergeResult.MergedItem, destinationItemGroup); AddItemToItemGroup(mergeResult.MergedItem, destinationItemGroup);
} }
@ -261,12 +266,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{ {
if (!string.Equals(item.ItemType, existingItem.ItemType, StringComparison.Ordinal)) if (!string.Equals(item.ItemType, existingItem.ItemType, StringComparison.Ordinal))
{ {
throw new InvalidOperationException("Cannot merge items of different types."); throw new InvalidOperationException(LocalizableStrings.CannotMergeItemsOfDifferentTypesError);
} }
if (!item.IntersectIncludes(existingItem).Any()) if (!item.IntersectIncludes(existingItem).Any())
{ {
throw new InvalidOperationException("Cannot merge items without a common include."); throw new InvalidOperationException(LocalizableStrings.CannotMergeItemsWithoutCommonIncludeError);
} }
var commonIncludes = item.IntersectIncludes(existingItem).ToList(); var commonIncludes = item.IntersectIncludes(existingItem).ToList();

View file

@ -20,12 +20,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{ {
if (typeof(T) != typeof(ProjectPropertyElement)) if (typeof(T) != typeof(ProjectPropertyElement))
{ {
throw new ArgumentException($"Expected element to be of type {nameof(ProjectPropertyElement)}, but got {nameof(T)}"); throw new ArgumentException(String.Format(LocalizableStrings.PropertyTransformApplicatorWrongElementTypeError, nameof(ProjectPropertyElement), nameof(T)));
} }
if (typeof(U) != typeof(ProjectPropertyGroupElement)) if (typeof(U) != typeof(ProjectPropertyGroupElement))
{ {
throw new ArgumentException($"Expected element to be of type {nameof(ProjectPropertyGroupElement)}, but got {nameof(U)}"); throw new ArgumentException(String.Format(LocalizableStrings.PropertyTransformApplicatorWrongElementTypeError, nameof(ProjectPropertyGroupElement), nameof(U)));
} }
if (element == null) if (element == null)
@ -41,12 +41,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
var mergedProperty = MergePropertyWithProject(property, destinationPropertyGroup); var mergedProperty = MergePropertyWithProject(property, destinationPropertyGroup);
if (mergedProperty != null && !string.IsNullOrEmpty(mergedProperty.Value)) if (mergedProperty != null && !string.IsNullOrEmpty(mergedProperty.Value))
{ {
TracePropertyInfo("Merging property, output merged property", mergedProperty); TracePropertyInfo(LocalizableStrings.MergingProperty, mergedProperty);
AddPropertyToPropertyGroup(mergedProperty, destinationPropertyGroup); AddPropertyToPropertyGroup(mergedProperty, destinationPropertyGroup);
} }
else else
{ {
TracePropertyInfo("Ignoring fully merged property", property); TracePropertyInfo(LocalizableStrings.IgnoringMergedProperty, property);
} }
} }
else else
@ -125,7 +125,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
private void TracePropertyInfo(string message, ProjectPropertyElement mergedProperty) private void TracePropertyInfo(string message, ProjectPropertyElement mergedProperty)
{ {
MigrationTrace.Instance.WriteLine($"{nameof(PropertyTransformApplicator)}: {message}, {{ Name={mergedProperty.Name}, Value={mergedProperty.Value} }}"); MigrationTrace.Instance.WriteLine(String.Format(
LocalizableStrings.PropertyInfo,
nameof(PropertyTransformApplicator),
message,
mergedProperty.Name,
mergedProperty.Value));
} }
} }
} }

View file

@ -35,7 +35,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
} }
else else
{ {
throw new ArgumentException($"Unexpected type {nameof(T)}"); throw new ArgumentException(String.Format(LocalizableStrings.UnexpectedTypeError, nameof(T)));
} }
} }

View file

@ -112,7 +112,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
var lastArg = Arguments.LastOrDefault(); var lastArg = Arguments.LastOrDefault();
if (lastArg != null && lastArg.MultipleValues) if (lastArg != null && lastArg.MultipleValues)
{ {
var message = string.Format("The last argument '{0}' accepts multiple values. No more argument can be added.", var message = string.Format(LocalizableStrings.LastArgumentMultiValueError,
lastArg.Name); lastArg.Name);
throw new InvalidOperationException(message); throw new InvalidOperationException(message);
} }
@ -266,7 +266,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
{ {
command.ShowHint(); command.ShowHint();
throw new CommandParsingException(command, throw new CommandParsingException(command,
$"Unexpected value '{optionComponents[1]}' for option '{optionName}'"); String.Format(LocalizableStrings.UnexpectedValueForOptionError, optionComponents[1], optionName));
} }
} }
else else
@ -284,7 +284,9 @@ namespace Microsoft.DotNet.Cli.CommandLine
if (!option.TryParse(arg)) if (!option.TryParse(arg))
{ {
command.ShowHint(); command.ShowHint();
throw new CommandParsingException(command, $"Unexpected value '{arg}' for option '{optionName}'"); throw new CommandParsingException(
command,
String.Format(LocalizableStrings.UnexpectedValueForOptionError, arg, optionName));
} }
} }
@ -312,7 +314,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
{ {
// Help option is special because we stop parsing once we see it // Help option is special because we stop parsing once we see it
// So we store it separately for further use // So we store it separately for further use
OptionHelp = Option(template, "Show help information", CommandOptionType.NoValue); OptionHelp = Option(template, LocalizableStrings.ShowHelpInfo, CommandOptionType.NoValue);
return OptionHelp; return OptionHelp;
} }
@ -338,7 +340,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
{ {
// Version option is special because we stop parsing once we see it // Version option is special because we stop parsing once we see it
// So we store it separately for further use // So we store it separately for further use
OptionVersion = Option(template, "Show version information", CommandOptionType.NoValue); OptionVersion = Option(template, LocalizableStrings.ShowVersionInfo, CommandOptionType.NoValue);
ShortVersionGetter = shortFormVersionGetter; ShortVersionGetter = shortFormVersionGetter;
LongVersionGetter = longFormVersionGetter ?? shortFormVersionGetter; LongVersionGetter = longFormVersionGetter ?? shortFormVersionGetter;
@ -350,14 +352,14 @@ namespace Microsoft.DotNet.Cli.CommandLine
{ {
if (OptionHelp != null) if (OptionHelp != null)
{ {
Console.WriteLine(string.Format("Specify --{0} for a list of available options and commands.", OptionHelp.LongName)); Console.WriteLine(string.Format(LocalizableStrings.ShowHintInfo, OptionHelp.LongName));
} }
} }
// Show full help // Show full help
public void ShowHelp(string commandName = null) public void ShowHelp(string commandName = null)
{ {
var headerBuilder = new StringBuilder("Usage:"); var headerBuilder = new StringBuilder(LocalizableStrings.UsageHeader);
var usagePrefixLength = headerBuilder.Length; var usagePrefixLength = headerBuilder.Length;
for (var cmd = this; cmd != null; cmd = cmd.Parent) for (var cmd = this; cmd != null; cmd = cmd.Parent)
{ {
@ -365,11 +367,11 @@ namespace Microsoft.DotNet.Cli.CommandLine
if (cmd != this && cmd.Arguments.Any()) if (cmd != this && cmd.Arguments.Any())
{ {
var args = string.Join(" ", cmd.Arguments.Select(arg => arg.Name)); var args = string.Join(" ", cmd.Arguments.Select(arg => arg.Name));
headerBuilder.Insert(usagePrefixLength, string.Format(" {0} {1}", cmd.Name, args)); headerBuilder.Insert(usagePrefixLength, string.Format(LocalizableStrings.UsageItemWithArgs, cmd.Name, args));
} }
else else
{ {
headerBuilder.Insert(usagePrefixLength, string.Format(" {0}", cmd.Name)); headerBuilder.Insert(usagePrefixLength, string.Format(LocalizableStrings.UsageItemWithoutArgs, cmd.Name));
} }
} }
@ -385,7 +387,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
if (target != null) if (target != null)
{ {
headerBuilder.AppendFormat(" {0}", commandName); headerBuilder.AppendFormat(LocalizableStrings.CommandItem, commandName);
} }
else else
{ {
@ -407,13 +409,13 @@ namespace Microsoft.DotNet.Cli.CommandLine
{ {
if (cmd == target) if (cmd == target)
{ {
headerBuilder.Append(" [arguments]"); headerBuilder.Append(LocalizableStrings.UsageArgumentsToken);
} }
if (argumentsBuilder.Length == 0) if (argumentsBuilder.Length == 0)
{ {
argumentsBuilder.AppendLine(); argumentsBuilder.AppendLine();
argumentsBuilder.AppendLine("Arguments:"); argumentsBuilder.AppendLine(LocalizableStrings.UsageArgumentsHeader);
} }
maxArgLen = Math.Max(maxArgLen, MaxArgumentLength(cmd.Arguments)); maxArgLen = Math.Max(maxArgLen, MaxArgumentLength(cmd.Arguments));
@ -424,7 +426,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
{ {
if (cmd.Arguments.Any()) if (cmd.Arguments.Any())
{ {
var outputFormat = " {0}{1}"; var outputFormat = LocalizableStrings.UsageArgumentItem;
foreach (var arg in cmd.Arguments) foreach (var arg in cmd.Arguments)
{ {
argumentsBuilder.AppendFormat( argumentsBuilder.AppendFormat(
@ -438,12 +440,12 @@ namespace Microsoft.DotNet.Cli.CommandLine
if (target.Options.Any()) if (target.Options.Any())
{ {
headerBuilder.Append(" [options]"); headerBuilder.Append(LocalizableStrings.UsageOptionsToken);
optionsBuilder.AppendLine(); optionsBuilder.AppendLine();
optionsBuilder.AppendLine("Options:"); optionsBuilder.AppendLine(LocalizableStrings.UsageOptionsHeader);
var maxOptLen = MaxOptionTemplateLength(target.Options); var maxOptLen = MaxOptionTemplateLength(target.Options);
var outputFormat = string.Format(" {{0, -{0}}}{{1}}", maxOptLen + 2); var outputFormat = string.Format(LocalizableStrings.UsageOptionsItem, maxOptLen + 2);
foreach (var opt in target.Options) foreach (var opt in target.Options)
{ {
optionsBuilder.AppendFormat(outputFormat, opt.Template, opt.Description); optionsBuilder.AppendFormat(outputFormat, opt.Template, opt.Description);
@ -453,12 +455,12 @@ namespace Microsoft.DotNet.Cli.CommandLine
if (target.Commands.Any()) if (target.Commands.Any())
{ {
headerBuilder.Append(" [command]"); headerBuilder.Append(LocalizableStrings.UsageCommandToken);
commandsBuilder.AppendLine(); commandsBuilder.AppendLine();
commandsBuilder.AppendLine("Commands:"); commandsBuilder.AppendLine(LocalizableStrings.UsageCommandsHeader);
var maxCmdLen = MaxCommandLength(target.Commands); var maxCmdLen = MaxCommandLength(target.Commands);
var outputFormat = string.Format(" {{0, -{0}}}{{1}}", maxCmdLen + 2); var outputFormat = string.Format(LocalizableStrings.UsageCommandsItem, maxCmdLen + 2);
foreach (var cmd in target.Commands.OrderBy(c => c.Name)) foreach (var cmd in target.Commands.OrderBy(c => c.Name))
{ {
commandsBuilder.AppendFormat(outputFormat, cmd.Name, cmd.Description); commandsBuilder.AppendFormat(outputFormat, cmd.Name, cmd.Description);
@ -468,7 +470,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
if (OptionHelp != null) if (OptionHelp != null)
{ {
commandsBuilder.AppendLine(); commandsBuilder.AppendLine();
commandsBuilder.AppendFormat("Use \"{0} [command] --help\" for more information about a command.", Name); commandsBuilder.AppendFormat(LocalizableStrings.UsageCommandsDetailHelp, Name);
commandsBuilder.AppendLine(); commandsBuilder.AppendLine();
} }
} }
@ -477,18 +479,18 @@ namespace Microsoft.DotNet.Cli.CommandLine
{ {
if (target.AllowArgumentSeparator) if (target.AllowArgumentSeparator)
{ {
headerBuilder.Append(" [[--] <arg>...]]"); headerBuilder.Append(LocalizableStrings.UsageCommandAdditionalArgs);
} }
else else
{ {
headerBuilder.Append(" [args]"); headerBuilder.Append(LocalizableStrings.UsageCommandArgs);
} }
if (!string.IsNullOrEmpty(target.ArgumentSeparatorHelpText)) if (!string.IsNullOrEmpty(target.ArgumentSeparatorHelpText))
{ {
argumentSeparatorBuilder.AppendLine(); argumentSeparatorBuilder.AppendLine();
argumentSeparatorBuilder.AppendLine("Args:"); argumentSeparatorBuilder.AppendLine(LocalizableStrings.UsageCommandsAdditionalArgsHeader);
argumentSeparatorBuilder.AppendLine($" {target.ArgumentSeparatorHelpText}"); argumentSeparatorBuilder.AppendLine(String.Format(LocalizableStrings.UsageCommandsAdditionalArgsItem, target.ArgumentSeparatorHelpText));
argumentSeparatorBuilder.AppendLine(); argumentSeparatorBuilder.AppendLine();
} }
} }
@ -515,7 +517,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
public string GetFullNameAndVersion() public string GetFullNameAndVersion()
{ {
return ShortVersionGetter == null ? FullName : string.Format("{0} {1}", FullName, ShortVersionGetter()); return ShortVersionGetter == null ? FullName : string.Format(LocalizableStrings.ShortVersionTemplate, FullName, ShortVersionGetter());
} }
public void ShowRootCommandFullNameAndVersion() public void ShowRootCommandFullNameAndVersion()
@ -565,7 +567,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
if (command._throwOnUnexpectedArg) if (command._throwOnUnexpectedArg)
{ {
command.ShowHint(); command.ShowHint();
throw new CommandParsingException(command, $"Unrecognized {argTypeName} '{args[index]}'"); throw new CommandParsingException(command, String.Format(LocalizableStrings.UnexpectedArgumentError, argTypeName, args[index]));
} }
else else
{ {
@ -612,7 +614,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
if (!File.Exists(fileName)) if (!File.Exists(fileName))
{ {
throw new InvalidOperationException($"Response file '{fileName}' doesn't exist."); throw new InvalidOperationException(String.Format(LocalizableStrings.ResponseFileNotFoundError, fileName));
} }
return File.ReadLines(fileName); return File.ReadLines(fileName);

View file

@ -45,13 +45,13 @@ namespace Microsoft.DotNet.Cli.CommandLine
} }
else else
{ {
throw new ArgumentException($"Invalid template pattern '{template}'", nameof(template)); throw new ArgumentException(String.Format(LocalizableStrings.InvalidTemplateError, nameof(template)));
} }
} }
if (string.IsNullOrEmpty(LongName) && string.IsNullOrEmpty(ShortName) && string.IsNullOrEmpty(SymbolName)) if (string.IsNullOrEmpty(LongName) && string.IsNullOrEmpty(ShortName) && string.IsNullOrEmpty(SymbolName))
{ {
throw new ArgumentException($"Invalid template pattern '{template}'", nameof(template)); throw new ArgumentException(LocalizableStrings.InvalidTemplateError, nameof(template));
} }
} }

View file

@ -5,6 +5,6 @@ namespace Microsoft.DotNet.Cli.CommandLine
{ {
internal class HelpMessageStrings internal class HelpMessageStrings
{ {
internal const string MSBuildAdditionalArgsHelpText = "Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options."; internal const string MSBuildAdditionalArgsHelpText = LocalizableStrings.MSBuildAdditionalArgsHelpText;
} }
} }

View file

@ -0,0 +1,61 @@
namespace Microsoft.DotNet.Cli.CommandLine
{
internal class LocalizableStrings
{
public const string LastArgumentMultiValueError = "The last argument '{0}' accepts multiple values. No more argument can be added.";
public const string UnexpectedValueForOptionError = "Unexpected value '{0}' for option '{1}'";
public const string UnexpectedArgumentError = "Unrecognized {0} '{1}'";
public const string ResponseFileNotFoundError = "Response file '{0}' doesn't exist.";
public const string ShowHelpInfo = "Show help information";
public const string ShowVersionInfo = "Show version information";
public const string ShowHintInfo = "Specify --{0} for a list of available options and commands.";
public const string UsageHeader = "Usage:";
public const string UsageItemWithoutArgs = " {0}";
public const string UsageItemWithArgs = " {0} {1}";
public const string UsageArgumentsToken = " [arguments]";
public const string UsageArgumentsHeader = "Arguments:";
public const string UsageArgumentItem = " {0}{1}";
public const string UsageOptionsToken = " [options]";
public const string UsageOptionsHeader = "Options:";
public const string UsageOptionsItem = " {{0, -{0}}}{{1}}";
public const string UsageCommandToken = " [command]";
public const string UsageCommandsHeader = "Commands:";
public const string UsageCommandsItem = " {{0, -{0}}}{{1}}";
public const string UsageCommandsDetailHelp = "Use \"{0} [command] --help\" for more information about a command.";
public const string UsageCommandArgs = " [args]";
public const string UsageCommandAdditionalArgs = " [[--] <additional arguments>...]]";
public const string UsageCommandsAdditionalArgsHeader = "Additional Arguments:";
public const string UsageCommandsAdditionalArgsItem = " {0}";
public const string CommandItem = " {0}";
public const string ShortVersionTemplate = "{0} {1}";
public const string InvalidTemplateError = "Invalid template pattern '{0}'";
public const string MSBuildAdditionalArgsHelpText = "Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options.";
}
}

View file

@ -0,0 +1,7 @@
namespace Microsoft.DotNet.Tools.MSBuild
{
internal class LocalizableStrings
{
public const string VerbosityOptionDescription = "Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]";
}
}

View file

@ -74,7 +74,7 @@ namespace Microsoft.DotNet.Tools.MSBuild
internal static CommandOption AddVerbosityOption(CommandLineApplication app) internal static CommandOption AddVerbosityOption(CommandLineApplication app)
{ {
return app.Option("-v|--verbosity", "Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]", CommandOptionType.SingleValue); return app.Option("-v|--verbosity", LocalizableStrings.VerbosityOptionDescription, CommandOptionType.SingleValue);
} }
private static string GetMSBuildExePath() private static string GetMSBuildExePath()

View file

@ -14,6 +14,9 @@
<Compile Include="..\..\src\Microsoft.DotNet.ProjectJsonMigration\MSBuildExtensions.cs"> <Compile Include="..\..\src\Microsoft.DotNet.ProjectJsonMigration\MSBuildExtensions.cs">
<Link>src\Microsoft.DotNet.ProjectJsonMigration\MSBuildExtensions.cs</Link> <Link>src\Microsoft.DotNet.ProjectJsonMigration\MSBuildExtensions.cs</Link>
</Compile> </Compile>
<Compile Include="..\..\src\Microsoft.DotNet.ProjectJsonMigration\LocalizableStrings.cs">
<Link>src\Microsoft.DotNet.ProjectJsonMigration\LocalizableStrings.cs</Link>
</Compile>
<EmbeddedResource Include="**\*.resx" /> <EmbeddedResource Include="**\*.resx" />
<EmbeddedResource Include="compiler\resources\**\*" /> <EmbeddedResource Include="compiler\resources\**\*" />
</ItemGroup> </ItemGroup>

View file

@ -25,8 +25,8 @@ Options:
-h|--help Show help information -h|--help Show help information
-f|--framework <FRAMEWORK> Add reference only when targetting a specific framework -f|--framework <FRAMEWORK> Add reference only when targetting a specific framework
Args: Additional Arguments:
Project to project references to add Project to project references to add
"; ";
const string FrameworkNet451Arg = "-f net451"; const string FrameworkNet451Arg = "-f net451";

View file

@ -24,8 +24,8 @@ Arguments:
Options: Options:
-h|--help Show help information -h|--help Show help information
Args: Additional Arguments:
Projects to add to solution Projects to add to solution
"; ";
[Theory] [Theory]

View file

@ -59,7 +59,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
[InlineData("run", true)] [InlineData("run", true)]
public void When_help_is_invoked_Then_MSBuild_extra_options_text_is_included_in_output(string commandName, bool isMSBuildCommand) public void When_help_is_invoked_Then_MSBuild_extra_options_text_is_included_in_output(string commandName, bool isMSBuildCommand)
{ {
const string MSBuildHelpText = " Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options."; const string MSBuildHelpText = " Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options.";
var projectDirectory = TestAssetsManager.CreateTestDirectory("ItContainsMSBuildHelpText"); var projectDirectory = TestAssetsManager.CreateTestDirectory("ItContainsMSBuildHelpText");
var result = new TestCommand("dotnet") var result = new TestCommand("dotnet")

View file

@ -24,8 +24,8 @@ Options:
-h|--help Show help information -h|--help Show help information
-f|--framework <FRAMEWORK> Remove reference only when targetting a specific framework -f|--framework <FRAMEWORK> Remove reference only when targetting a specific framework
Args: Additional Arguments:
Project to project references to remove Project to project references to remove
"; ";
const string FrameworkNet451Arg = "-f net451"; const string FrameworkNet451Arg = "-f net451";

View file

@ -22,8 +22,8 @@ Arguments:
Options: Options:
-h|--help Show help information -h|--help Show help information
Args: Additional Arguments:
Projects to remove from a solution Projects to remove from a solution
"; ";
[Theory] [Theory]

View file

@ -63,7 +63,7 @@ Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to se
Telemetry Telemetry
-------------- --------------
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community. The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include command-line arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell. You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry. You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.