dotnet-resgen should use a file to accept argument values
This commit is contained in:
parent
7a203c02e1
commit
7a03c91350
3 changed files with 148 additions and 96 deletions
|
@ -314,14 +314,12 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
success &= GenerateCultureResourceAssemblies(context.ProjectFile, dependencies, outputPath);
|
success &= GenerateCultureResourceAssemblies(context.ProjectFile, dependencies, intermediateOutputPath, outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PrintSummary(diagnostics, sw, success);
|
return PrintSummary(diagnostics, sw, success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static void RunScripts(ProjectContext context, string name, Dictionary<string, string> contextVariables)
|
private static void RunScripts(ProjectContext context, string name, Dictionary<string, string> contextVariables)
|
||||||
{
|
{
|
||||||
foreach (var script in context.ProjectFile.Scripts.GetOrEmpty(name))
|
foreach (var script in context.ProjectFile.Scripts.GetOrEmpty(name))
|
||||||
|
@ -370,16 +368,18 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
{
|
{
|
||||||
if (ResourceUtility.IsResxFile(resgenFile.InputFile))
|
if (ResourceUtility.IsResxFile(resgenFile.InputFile))
|
||||||
{
|
{
|
||||||
|
var arguments = new[]
|
||||||
|
{
|
||||||
|
resgenFile.InputFile,
|
||||||
|
$"-o:{resgenFile.OutputFile}",
|
||||||
|
$"-v:{project.Version.Version}"
|
||||||
|
};
|
||||||
|
|
||||||
|
var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen-resx.rsp");
|
||||||
|
File.WriteAllLines(rsp, arguments);
|
||||||
|
|
||||||
var result =
|
var result =
|
||||||
Command.CreateDotNet("resgen",
|
Command.CreateDotNet("resgen", new[] { $"@{rsp}" })
|
||||||
new string[]
|
|
||||||
{
|
|
||||||
$"{resgenFile.InputFile}",
|
|
||||||
"-o",
|
|
||||||
$"{resgenFile.OutputFile}",
|
|
||||||
"-v",
|
|
||||||
$"{project.Version.Version}"
|
|
||||||
})
|
|
||||||
.ForwardStdErr()
|
.ForwardStdErr()
|
||||||
.ForwardStdOut()
|
.ForwardStdOut()
|
||||||
.Execute();
|
.Execute();
|
||||||
|
@ -400,11 +400,14 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool GenerateCultureResourceAssemblies(Project project, List<LibraryExport> dependencies, string outputPath)
|
private static bool GenerateCultureResourceAssemblies(
|
||||||
|
Project project,
|
||||||
|
List<LibraryExport> dependencies,
|
||||||
|
string intermediateOutputPath,
|
||||||
|
string outputPath)
|
||||||
{
|
{
|
||||||
var referencePaths = CompilerUtil.GetReferencePathsForCultureResgen(dependencies);
|
var referencePaths = CompilerUtil.GetReferencePathsForCultureResgen(dependencies);
|
||||||
var resgenReferenceArgs = referencePaths.Select(referencePath => $"-r \"{referencePath}\"").ToList();
|
var resgenReferenceArgs = referencePaths.Select(path => $"-r:{path}").ToList();
|
||||||
|
|
||||||
var cultureResgenFiles = CompilerUtil.GetCultureResources(project, outputPath);
|
var cultureResgenFiles = CompilerUtil.GetCultureResources(project, outputPath);
|
||||||
|
|
||||||
foreach (var resgenFile in cultureResgenFiles)
|
foreach (var resgenFile in cultureResgenFiles)
|
||||||
|
@ -419,15 +422,17 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
var arguments = new List<string>();
|
var arguments = new List<string>();
|
||||||
|
|
||||||
arguments.AddRange(resgenReferenceArgs);
|
arguments.AddRange(resgenReferenceArgs);
|
||||||
arguments.Add($"-o \"{resgenFile.OutputFile}\"");
|
arguments.Add($"-o:{resgenFile.OutputFile}");
|
||||||
arguments.Add($"-c {resgenFile.Culture}");
|
arguments.Add($"-c:{resgenFile.Culture}");
|
||||||
arguments.Add($"-v {project.Version.Version}");
|
arguments.Add($"-v:{project.Version.Version}");
|
||||||
arguments.AddRange(resgenFile.InputFileToMetadata.Select(fileToMetadata => $"\"{fileToMetadata.Key}\",{fileToMetadata.Value}"));
|
arguments.AddRange(resgenFile.InputFileToMetadata.Select(fileToMetadata => $"{fileToMetadata.Key},{fileToMetadata.Value}"));
|
||||||
|
var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen.rsp");
|
||||||
|
File.WriteAllLines(rsp, arguments);
|
||||||
|
|
||||||
var result = Command.CreateDotNet("resgen", arguments)
|
var result = Command.CreateDotNet("resgen", new[] { $"@{rsp}" })
|
||||||
.ForwardStdErr()
|
.ForwardStdErr()
|
||||||
.ForwardStdOut()
|
.ForwardStdOut()
|
||||||
.Execute();
|
.Execute();
|
||||||
if (result.ExitCode != 0)
|
if (result.ExitCode != 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -2,10 +2,7 @@
|
||||||
// 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;
|
||||||
using System.IO;
|
using System.CommandLine;
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
|
||||||
using Microsoft.DotNet.Cli.Compiler.Common;
|
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Resgen
|
namespace Microsoft.DotNet.Tools.Resgen
|
||||||
|
@ -16,68 +13,54 @@ namespace Microsoft.DotNet.Tools.Resgen
|
||||||
{
|
{
|
||||||
DebugHelper.HandleDebugSwitch(ref args);
|
DebugHelper.HandleDebugSwitch(ref args);
|
||||||
|
|
||||||
var app = new CommandLineApplication(false);
|
var help = false;
|
||||||
app.Name = "resgen";
|
string helpText = null;
|
||||||
app.FullName = "Resource compiler";
|
var returnCode = 0;
|
||||||
app.Description = "Microsoft (R) .NET Resource Generator";
|
|
||||||
app.HelpOption("-h|--help");
|
|
||||||
|
|
||||||
var ouputFile = app.Option("-o", "Output file name", CommandOptionType.SingleValue);
|
var resgenCommand = new ResgenCommand();
|
||||||
var culture = app.Option("-c", "Ouput assembly culture", CommandOptionType.SingleValue);
|
try
|
||||||
var version = app.Option("-v", "Ouput assembly version", CommandOptionType.SingleValue);
|
|
||||||
var references = app.Option("-r", "Compilation references", CommandOptionType.MultipleValue);
|
|
||||||
var inputFiles = app.Argument("<input>", "Input files", true);
|
|
||||||
|
|
||||||
app.OnExecute(() =>
|
|
||||||
{
|
{
|
||||||
if (!inputFiles.Values.Any())
|
ArgumentSyntax.Parse(args, syntax =>
|
||||||
{
|
{
|
||||||
Reporter.Error.WriteLine("No input files specified");
|
syntax.ApplicationName = "Resource compiler";
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var intputResourceFiles = inputFiles.Values.Select(ParseInputFile).ToArray();
|
syntax.HandleHelp = false;
|
||||||
var outputResourceFile = ResourceFile.Create(ouputFile.Value());
|
syntax.HandleErrors = false;
|
||||||
|
|
||||||
switch (outputResourceFile.Type)
|
syntax.DefineOption("o|output", ref resgenCommand.OutputFileName, "Output file name");
|
||||||
{
|
syntax.DefineOption("c|culture", ref resgenCommand.AssemblyCulture, "Ouput assembly culture");
|
||||||
case ResourceFileType.Dll:
|
syntax.DefineOption("v|version", ref resgenCommand.AssemblyVersion, "Ouput assembly version");
|
||||||
using (var outputStream = outputResourceFile.File.Create())
|
syntax.DefineOption("h|help", ref help, "Help for compile native.");
|
||||||
{
|
|
||||||
var metadata = new AssemblyInfoOptions();
|
|
||||||
metadata.Culture = culture.Value();
|
|
||||||
metadata.AssemblyVersion = version.Value();
|
|
||||||
|
|
||||||
ResourceAssemblyGenerator.Generate(intputResourceFiles,
|
syntax.DefineOptionList("r", ref resgenCommand.CompilationReferences, "Compilation references");
|
||||||
outputStream,
|
syntax.DefineParameterList("args", ref resgenCommand.Args, "Input files");
|
||||||
metadata,
|
|
||||||
Path.GetFileNameWithoutExtension(outputResourceFile.File.Name),
|
|
||||||
references.Values.ToArray()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ResourceFileType.Resources:
|
|
||||||
using (var outputStream = outputResourceFile.File.Create())
|
|
||||||
{
|
|
||||||
if (intputResourceFiles.Length > 1)
|
|
||||||
{
|
|
||||||
Reporter.Error.WriteLine("Only one input file required when generating .resource output");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ResourcesFileGenerator.Generate(intputResourceFiles.Single().Resource, outputStream);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Reporter.Error.WriteLine("Resx output type not supported");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
helpText = syntax.GetHelpText();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
catch (ArgumentSyntaxException exception)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
help = true;
|
||||||
|
returnCode = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resgenCommand.Args.Count == 0)
|
||||||
|
{
|
||||||
|
Reporter.Error.WriteLine("No input files specified");
|
||||||
|
help = true;
|
||||||
|
returnCode = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (help)
|
||||||
|
{
|
||||||
|
Console.WriteLine(helpText);
|
||||||
|
return returnCode;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return app.Execute(args);
|
return resgenCommand.Execute();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -90,22 +73,5 @@ namespace Microsoft.DotNet.Tools.Resgen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ResourceSource ParseInputFile(string arg)
|
|
||||||
{
|
|
||||||
var seperatorIndex = arg.IndexOf(',');
|
|
||||||
string name = null;
|
|
||||||
string metadataName = null;
|
|
||||||
if (seperatorIndex > 0)
|
|
||||||
{
|
|
||||||
name = arg.Substring(0, seperatorIndex);
|
|
||||||
metadataName = arg.Substring(seperatorIndex + 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
name = arg;
|
|
||||||
metadataName = arg;
|
|
||||||
}
|
|
||||||
return new ResourceSource(ResourceFile.Create(name), metadataName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
81
src/dotnet/commands/dotnet-resgen/ResgenCommand.cs
Normal file
81
src/dotnet/commands/dotnet-resgen/ResgenCommand.cs
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.DotNet.Cli.Compiler.Common;
|
||||||
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Tools.Resgen
|
||||||
|
{
|
||||||
|
public partial class ResgenCommand
|
||||||
|
{
|
||||||
|
public string OutputFileName = null;
|
||||||
|
public string AssemblyCulture = null;
|
||||||
|
public string AssemblyVersion = null;
|
||||||
|
public IReadOnlyList<string> CompilationReferences = null;
|
||||||
|
public IReadOnlyList<string> Args = null;
|
||||||
|
|
||||||
|
public int Execute()
|
||||||
|
{
|
||||||
|
var intputResourceFiles = Args.Select(ParseInputFile).ToArray();
|
||||||
|
var outputResourceFile = ResourceFile.Create(OutputFileName);
|
||||||
|
|
||||||
|
switch (outputResourceFile.Type)
|
||||||
|
{
|
||||||
|
case ResourceFileType.Dll:
|
||||||
|
using (var outputStream = outputResourceFile.File.Create())
|
||||||
|
{
|
||||||
|
var metadata = new AssemblyInfoOptions
|
||||||
|
{
|
||||||
|
Culture = AssemblyCulture,
|
||||||
|
AssemblyVersion = AssemblyVersion,
|
||||||
|
};
|
||||||
|
|
||||||
|
ResourceAssemblyGenerator.Generate(intputResourceFiles,
|
||||||
|
outputStream,
|
||||||
|
metadata,
|
||||||
|
Path.GetFileNameWithoutExtension(outputResourceFile.File.Name),
|
||||||
|
CompilationReferences.ToArray());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ResourceFileType.Resources:
|
||||||
|
using (var outputStream = outputResourceFile.File.Create())
|
||||||
|
{
|
||||||
|
if (intputResourceFiles.Length > 1)
|
||||||
|
{
|
||||||
|
Reporter.Error.WriteLine("Only one input file required when generating .resource output");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
ResourcesFileGenerator.Generate(intputResourceFiles.Single().Resource, outputStream);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Reporter.Error.WriteLine("Resx output type not supported");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ResourceSource ParseInputFile(string arg)
|
||||||
|
{
|
||||||
|
var seperatorIndex = arg.IndexOf(',');
|
||||||
|
string name;
|
||||||
|
string metadataName;
|
||||||
|
if (seperatorIndex > 0)
|
||||||
|
{
|
||||||
|
name = arg.Substring(0, seperatorIndex);
|
||||||
|
metadataName = arg.Substring(seperatorIndex + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
name = arg;
|
||||||
|
metadataName = arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResourceSource(ResourceFile.Create(name), metadataName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue