示例#1
0
        protected virtual void ProcessContext(ProjectContext context)
        {
            PopulateDependencies(context);

            var inputFolder = ArtifactPathsCalculator.InputPathForContext(context);
            var outputName  = GetProjectOutputName(context.TargetFramework);

            var resourceCultures = context.ProjectFile.Files.ResourceFiles
                                   .Select(resourceFile => ResourceUtility.GetResourceCultureName(resourceFile.Key))
                                   .Distinct();

            foreach (var culture in resourceCultures)
            {
                if (string.IsNullOrEmpty(culture))
                {
                    continue;
                }

                var resourceFilePath = Path.Combine(culture, $"{Project.Name}.resources.dll");
                TryAddOutputFile(context, inputFolder, resourceFilePath);
            }

            TryAddOutputFile(context, inputFolder, outputName);
            TryAddOutputFile(context, inputFolder, $"{Project.Name}.xml");
            TryAddOutputFile(context, inputFolder, $"{Project.Name}.runtimeconfig.json");
        }
示例#2
0
 public static List <NonCultureResgenIO> GetNonCultureResources(Project project, string intermediateOutputPath)
 {
     return
         ((from resourceFile in project.Files.ResourceFiles
           let inputFile = resourceFile.Key
                           where string.IsNullOrEmpty(ResourceUtility.GetResourceCultureName(inputFile))
                           let metadataName = GetResourceFileMetadataName(project, resourceFile.Key, resourceFile.Value)
                                              let outputFile = ResourceUtility.IsResxFile(inputFile) ? Path.Combine(intermediateOutputPath, metadataName) : null
                                                               select new NonCultureResgenIO(inputFile, outputFile, metadataName))
          .ToList());
 }
示例#3
0
        public virtual IEnumerable <string> Resources()
        {
            var resourceNames = Project.Files.ResourceFiles
                                .Select(f => ResourceUtility.GetResourceCultureName(f.Key))
                                .Where(f => !string.IsNullOrEmpty(f))
                                .Distinct();

            foreach (var resourceName in resourceNames)
            {
                yield return(Path.Combine(BasePath, resourceName, Project.Name + ".resources" + FileNameSuffixes.DotNet.DynamicLib));
            }
        }
示例#4
0
        public static List <NonCultureResgenIO> GetNonCultureResourcesFromIncludeEntries(Project project, string intermediateOutputPath, CommonCompilerOptions compilationOptions)
        {
            var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilationOptions.EmbedInclude, "/", diagnostics: null);

            return
                ((from resourceFile in includeFiles
                  let inputFile = resourceFile.SourcePath
                                  where string.IsNullOrEmpty(ResourceUtility.GetResourceCultureName(inputFile))
                                  let target = resourceFile.IsCustomTarget ? resourceFile.TargetPath : null
                                               let metadataName = GetResourceFileMetadataName(project, resourceFile.SourcePath, target)
                                                                  let outputFile = ResourceUtility.IsResxFile(inputFile) ? Path.Combine(intermediateOutputPath, metadataName) : null
                                                                                   select new NonCultureResgenIO(inputFile, outputFile, metadataName))
                 .ToList());
        }
示例#5
0
 // used in incremental compilation
 public static List <CultureResgenIO> GetCultureResources(Project project, string outputPath)
 {
     return
         ((from resourceFileGroup in project.Files.ResourceFiles.GroupBy(
               resourceFile => ResourceUtility.GetResourceCultureName(resourceFile.Key))
           let culture = resourceFileGroup.Key
                         where !string.IsNullOrEmpty(culture)
                         let inputFileToMetadata = resourceFileGroup.ToDictionary(
               r => r.Key,
               r => GetResourceFileMetadataName(project, r.Key, r.Value))
                                                   let resourceOutputPath = Path.Combine(outputPath, culture)
                                                                            let outputFile = Path.Combine(resourceOutputPath, project.Name + ".resources.dll")
                                                                                             select new CultureResgenIO(culture, inputFileToMetadata, outputFile)
           ).ToList());
 }
示例#6
0
        public static List <CultureResgenIO> GetCultureResourcesFromIncludeEntries(Project project, string outputPath, CommonCompilerOptions compilationOptions)
        {
            var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilationOptions.EmbedInclude, "/", diagnostics: null);

            return
                ((from resourceFileGroup in includeFiles
                  .GroupBy(resourceFile => ResourceUtility.GetResourceCultureName(resourceFile.SourcePath))
                  let culture = resourceFileGroup.Key
                                where !string.IsNullOrEmpty(culture)
                                let inputFileToMetadata = resourceFileGroup.ToDictionary(
                      r => r.SourcePath, r => GetResourceFileMetadataName(project, r.SourcePath, r.IsCustomTarget ? r.TargetPath : null))
                                                          let resourceOutputPath = Path.Combine(outputPath, culture)
                                                                                   let outputFile = Path.Combine(resourceOutputPath, project.Name + ".resources.dll")
                                                                                                    select new CultureResgenIO(culture, inputFileToMetadata, outputFile))
                 .ToList());
        }
示例#7
0
        protected virtual void ProcessContext(ProjectContext context)
        {
            PopulateDependencies(context);

            var inputFolder = ArtifactPathsCalculator.InputPathForContext(context);

            var compilerOptions = Project.GetCompilerOptions(context.TargetFramework, Configuration);
            var outputName      = compilerOptions.OutputName;
            var outputExtension =
                context.TargetFramework.IsDesktop() && compilerOptions.EmitEntryPoint.GetValueOrDefault()
                    ? ".exe" : ".dll";

            IEnumerable <string> resourceCultures = null;

            if (compilerOptions.EmbedInclude == null)
            {
                resourceCultures = context.ProjectFile.Files.ResourceFiles
                                   .Select(resourceFile => ResourceUtility.GetResourceCultureName(resourceFile.Key))
                                   .Distinct();
            }
            else
            {
                var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilerOptions.EmbedInclude, "/", diagnostics: null);
                resourceCultures = includeFiles
                                   .Select(file => ResourceUtility.GetResourceCultureName(file.SourcePath))
                                   .Distinct();
            }

            foreach (var culture in resourceCultures)
            {
                if (string.IsNullOrEmpty(culture))
                {
                    continue;
                }

                var resourceFilePath = Path.Combine(culture, $"{outputName}.resources.dll");
                TryAddOutputFile(context, inputFolder, resourceFilePath);
            }

            TryAddOutputFile(context, inputFolder, outputName + outputExtension);
            TryAddOutputFile(context, inputFolder, $"{outputName}.xml");
            TryAddOutputFile(context, inputFolder, $"{outputName}.runtimeconfig.json");
        }
示例#8
0
文件: Program.cs 项目: NabidAlam/cli
        private static bool AddResources(Project project, List <string> compilerArgs, string intermediateOutputPath)
        {
            foreach (var resourceFile in project.Files.ResourceFiles)
            {
                var resourcePath = resourceFile.Key;

                if (!string.IsNullOrEmpty(ResourceUtility.GetResourceCultureName(resourcePath)))
                {
                    // Include only "neutral" resources into main assembly
                    continue;
                }

                var name = GetResourceFileMetadataName(project, resourceFile);

                var fileName = resourcePath;

                if (ResourceUtility.IsResxFile(fileName))
                {
                    // {file}.resx -> {file}.resources
                    var resourcesFile = Path.Combine(intermediateOutputPath, name);

                    var result = Command.Create("dotnet-resgen", $"\"{fileName}\" -o \"{resourcesFile}\" -v \"{project.Version.Version}\"")
                                 .ForwardStdErr()
                                 .ForwardStdOut()
                                 .Execute();

                    if (result.ExitCode != 0)
                    {
                        return(false);
                    }

                    // Use this as the resource name instead
                    fileName = resourcesFile;
                }

                compilerArgs.Add($"--resource:\"{fileName}\",{name}");
            }

            return(true);
        }
示例#9
0
文件: Program.cs 项目: NabidAlam/cli
        private static bool GenerateResourceAssemblies(Project project, List <LibraryExport> dependencies, string outputPath, string configuration)
        {
            var references = dependencies.SelectMany(libraryExport => libraryExport.CompilationAssemblies);

            foreach (var resourceFileGroup in project.Files.ResourceFiles.GroupBy(file => ResourceUtility.GetResourceCultureName(file.Key)))
            {
                var culture = resourceFileGroup.Key;
                if (!string.IsNullOrEmpty(culture))
                {
                    var resourceOutputPath = Path.Combine(outputPath, culture);

                    if (!Directory.Exists(resourceOutputPath))
                    {
                        Directory.CreateDirectory(resourceOutputPath);
                    }

                    var resourceOuputFile = Path.Combine(resourceOutputPath, project.Name + ".resources.dll");

                    var arguments = new List <string>();
                    arguments.AddRange(references.Select(r => $"-r \"{r.ResolvedPath}\""));
                    arguments.Add($"-o \"{resourceOuputFile}\"");
                    arguments.Add($"-c {culture}");
                    arguments.Add($"-v {project.Version.Version}");

                    foreach (var resourceFile in resourceFileGroup)
                    {
                        var metadataName = GetResourceFileMetadataName(project, resourceFile);
                        arguments.Add($"\"{resourceFile.Key}\",{metadataName}");
                    }

                    var result = Command.Create("dotnet-resgen", arguments)
                                 .ForwardStdErr()
                                 .ForwardStdOut()
                                 .Execute();
                    if (result.ExitCode != 0)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }