Пример #1
0
        private static Stream GenerateResources(ResourceFile resourceFile)
        {
            var stream = new MemoryStream();

            ResourcesFileGenerator.Generate(resourceFile, stream);
            stream.Position = 0;
            return(stream);
        }
Пример #2
0
        public int Execute()
        {
            var inputResourceFiles = 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(inputResourceFiles,
                                                       outputStream,
                                                       metadata,
                                                       Path.GetFileNameWithoutExtension(outputResourceFile.File.Name),
                                                       CompilationReferences.ToArray()
                                                       );
                }
                break;

            case ResourceFileType.Resources:
                using (var outputStream = outputResourceFile.File.Create())
                {
                    if (inputResourceFiles.Length > 1)
                    {
                        Reporter.Error.WriteLine("Only one input file required when generating .resource output");
                        return(1);
                    }
                    ResourcesFileGenerator.Generate(inputResourceFiles.Single().Resource, outputStream);
                }
                break;

            default:
                Reporter.Error.WriteLine("Resx output type not supported");
                return(1);
            }

            return(0);
        }
Пример #3
0
        public static int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication(false);

            app.Name        = "resgen";
            app.FullName    = "Resource compiler";
            app.Description = "Microsoft (R) .NET Resource Generator";
            app.HelpOption("-h|--help");

            var ouputFile  = app.Option("-o", "Output file name", CommandOptionType.SingleValue);
            var culture    = app.Option("-c", "Ouput assembly culture", CommandOptionType.SingleValue);
            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())
                {
                    Reporter.Error.WriteLine("No input files specified");
                    return(1);
                }

                var intputResourceFiles = inputFiles.Values.Select(ParseInputFile).ToArray();
                var outputResourceFile  = ResourceFile.Create(ouputFile.Value());

                switch (outputResourceFile.Type)
                {
                case ResourceFileType.Dll:
                    using (var outputStream = outputResourceFile.File.Create())
                    {
                        var metadata             = new AssemblyInfoOptions();
                        metadata.Culture         = culture.Value();
                        metadata.AssemblyVersion = version.Value();

                        ResourceAssemblyGenerator.Generate(intputResourceFiles,
                                                           outputStream,
                                                           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);
            });

            try
            {
                return(app.Execute(args));
            }
            catch (Exception ex)
            {
#if DEBUG
                Reporter.Error.WriteLine(ex.ToString());
#else
                Reporter.Error.WriteLine(ex.Message);
#endif
                return(1);
            }
        }