2015-12-14 16:33:11 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
2015-11-16 19:21:57 +00:00
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
2016-01-05 07:12:40 +00:00
|
|
|
|
using System;
|
2015-11-16 19:21:57 +00:00
|
|
|
|
using System.IO;
|
2015-11-17 01:02:04 +00:00
|
|
|
|
using System.Linq;
|
2015-10-19 04:07:48 +00:00
|
|
|
|
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
2016-01-05 07:12:40 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Compiler.Common;
|
2015-10-19 04:07:48 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Resgen
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
public static int Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
|
2015-12-14 16:33:11 +00:00
|
|
|
|
var app = new CommandLineApplication(false);
|
2015-10-19 04:07:48 +00:00
|
|
|
|
app.Name = "resgen";
|
|
|
|
|
app.FullName = "Resource compiler";
|
|
|
|
|
app.Description = "Microsoft (R) .NET Resource Generator";
|
|
|
|
|
app.HelpOption("-h|--help");
|
|
|
|
|
|
2015-12-14 16:33:11 +00:00
|
|
|
|
var ouputFile = app.Option("-o", "Output file name", CommandOptionType.SingleValue);
|
|
|
|
|
var culture = app.Option("-c", "Ouput assembly culture", CommandOptionType.SingleValue);
|
2015-12-14 18:05:38 +00:00
|
|
|
|
var version = app.Option("-v", "Ouput assembly version", CommandOptionType.SingleValue);
|
2015-12-14 16:33:11 +00:00
|
|
|
|
var references = app.Option("-r", "Compilation references", CommandOptionType.MultipleValue);
|
|
|
|
|
var inputFiles = app.Argument("<input>", "Input files", true);
|
2015-10-19 04:07:48 +00:00
|
|
|
|
|
|
|
|
|
app.OnExecute(() =>
|
|
|
|
|
{
|
2015-12-14 16:33:11 +00:00
|
|
|
|
if (!inputFiles.Values.Any())
|
|
|
|
|
{
|
|
|
|
|
Reporter.Error.WriteLine("No input files specified");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2015-10-19 04:07:48 +00:00
|
|
|
|
|
2015-12-14 16:33:11 +00:00
|
|
|
|
var intputResourceFiles = inputFiles.Values.Select(ParseInputFile).ToArray();
|
|
|
|
|
var outputResourceFile = ResourceFile.Create(ouputFile.Value());
|
2015-10-19 04:07:48 +00:00
|
|
|
|
|
2015-12-14 16:33:11 +00:00
|
|
|
|
switch (outputResourceFile.Type)
|
2015-10-19 04:07:48 +00:00
|
|
|
|
{
|
2015-12-14 16:33:11 +00:00
|
|
|
|
case ResourceFileType.Dll:
|
|
|
|
|
using (var outputStream = outputResourceFile.File.Create())
|
|
|
|
|
{
|
2015-12-14 18:05:38 +00:00
|
|
|
|
var metadata = new AssemblyInfoOptions();
|
|
|
|
|
metadata.Culture = culture.Value();
|
|
|
|
|
metadata.AssemblyVersion = version.Value();
|
|
|
|
|
|
2015-12-14 16:33:11 +00:00
|
|
|
|
ResourceAssemblyGenerator.Generate(intputResourceFiles,
|
|
|
|
|
outputStream,
|
2015-12-14 18:05:38 +00:00
|
|
|
|
metadata,
|
2015-12-14 16:33:11 +00:00
|
|
|
|
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;
|
2015-10-19 04:07:48 +00:00
|
|
|
|
}
|
2015-12-14 16:33:11 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return app.Execute(args);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Reporter.Error.WriteLine(ex.ToString());
|
|
|
|
|
#else
|
|
|
|
|
Reporter.Error.WriteLine(ex.Message);
|
|
|
|
|
#endif
|
|
|
|
|
return 1;
|
2015-11-17 01:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-14 16:33:11 +00:00
|
|
|
|
private static ResourceSource ParseInputFile(string arg)
|
2015-11-17 01:02:04 +00:00
|
|
|
|
{
|
2015-12-14 16:33:11 +00:00
|
|
|
|
var seperatorIndex = arg.IndexOf(',');
|
|
|
|
|
string name = null;
|
|
|
|
|
string metadataName = null;
|
|
|
|
|
if (seperatorIndex > 0)
|
2015-11-17 01:02:04 +00:00
|
|
|
|
{
|
2015-12-14 16:33:11 +00:00
|
|
|
|
name = arg.Substring(0, seperatorIndex);
|
|
|
|
|
metadataName = arg.Substring(seperatorIndex + 1);
|
2015-10-19 04:07:48 +00:00
|
|
|
|
}
|
2015-12-14 16:33:11 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
name = arg;
|
|
|
|
|
metadataName = arg;
|
|
|
|
|
}
|
|
|
|
|
return new ResourceSource(ResourceFile.Create(name), metadataName);
|
2015-10-19 04:07:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|