Beispiel #1
0
        public static bool GenerateCultureResourceAssemblies(Project project, List <CompilerUtility.CultureResgenIO> cultureResgenFiles, List <string> referencePaths, IList <string> diagnostics)
        {
            foreach (var resgenFile in cultureResgenFiles)
            {
                var resourceOutputPath = Path.GetDirectoryName(resgenFile.OutputFile);
                Directory.CreateDirectory(resourceOutputPath);

                var inputResourceFiles = resgenFile.InputFileToMetadata
                                         .Select(fileToMetadata => new ResourceSource(ResourceFile.Create(fileToMetadata.Key), fileToMetadata.Value))
                                         .ToArray();

                var outputResourceFile = ResourceFile.Create(resgenFile.OutputFile);

                if (outputResourceFile.Type != ResourceFileType.Dll)
                {
                    diagnostics.Add("Resource output type not supported");
                    return(false);
                }

                using (var outputStream = outputResourceFile.File.Create())
                {
                    var metadata = new AssemblyInfoOptions
                    {
                        Culture         = resgenFile.Culture,
                        AssemblyVersion = project.Version.Version.ToString(),
                    };

                    ResourceAssemblyGenerator.Generate(inputResourceFiles,
                                                       outputStream,
                                                       metadata,
                                                       Path.GetFileNameWithoutExtension(outputResourceFile.File.Name),
                                                       referencePaths.ToArray(),
                                                       diagnostics);
                }
            }

            return(true);
        }
Beispiel #2
0
        public static bool GenerateNonCultureResources(Project project, List <CompilerUtility.NonCultureResgenIO> resgenFiles, IList <string> diagnostics)
        {
            foreach (var resgenFile in resgenFiles)
            {
                if (ResourceUtility.IsResxFile(resgenFile.InputFile))
                {
                    var outputResourceFile = ResourceFile.Create(resgenFile.OutputFile);

                    if (outputResourceFile.Type != ResourceFileType.Resources)
                    {
                        diagnostics.Add("Resource output type not supported");
                        return(false);
                    }

                    using (var outputStream = outputResourceFile.File.Create())
                    {
                        var resourceSource = new ResourceSource(ResourceFile.Create(resgenFile.InputFile), resgenFile.InputFile);
                        ResourceFileGenerator.Generate(resourceSource.Resource, outputStream);
                    }
                }
            }

            return(true);
        }