Пример #1
0
        private void CompileResXFiles(Configuration solutionConfiguration)
        {
            Log(Level.Verbose, "Compiling resources:");

            Hashtable resxResources = new Hashtable();

            // neutral resources
            foreach (Resource resource in _neutralResources) {
                if (!resource.IsResX) {
                    continue;
                }

                Log(Level.Verbose, " - {0}", resource.InputFile);

                // determine filename of output file
                FileInfo compiledResxFile = resource.GetCompiledResourceFile(solutionConfiguration);
                // add to list of resx files to compile
                resxResources.Add(resource, compiledResxFile);
            }

            // localized resources
            foreach (Resource resource in _localizedResources) {
                if (!resource.IsResX) {
                    continue;
                }

                Log(Level.Verbose, " - {0}", resource.InputFile);

                // determine filename of output file
                FileInfo compiledResxFile = resource.GetCompiledResourceFile(solutionConfiguration);
                // add to list of resx files to compile
                resxResources.Add(resource, compiledResxFile);
            }

            // no further processing required if there are no resx files to
            // compile
            if (resxResources.Count == 0) {
                return;
            }

            // create instance of ResGen task
            ResGenTask rt = new ResGenTask();

            // inherit project from solution task
            rt.Project = SolutionTask.Project;

            // inherit namespace manager from solution task
            rt.NamespaceManager = SolutionTask.NamespaceManager;

            // parent is solution task
            rt.Parent = SolutionTask;

            // inherit verbose setting from solution task
            rt.Verbose = SolutionTask.Verbose;

            // make sure framework specific information is set
            rt.InitializeTaskConfiguration();

            // set parent of child elements
            rt.Assemblies.Parent = rt;

            // inherit project from solution task from parent task
            rt.Assemblies.Project = rt.Project;

            // inherit namespace manager from parent task
            rt.Assemblies.NamespaceManager = rt.NamespaceManager;

            // set base directory for filesets
            rt.Assemblies.BaseDirectory = ProjectDirectory;

            // set resx files to compile
            foreach (DictionaryEntry entry in resxResources) {
                Resource resource = (Resource) entry.Key;
                FileInfo outputFile = (FileInfo) entry.Value;

                QualifiedResource qualifiedResource = new QualifiedResource(
                    resource.InputFile, outputFile);

                rt.QualifiedResources.Add(qualifiedResource);
            }

            // inherit assembly references from project
            foreach (ReferenceBase reference in References) {
                StringCollection assemblyReferences = reference.GetAssemblyReferences(
                    solutionConfiguration);
                foreach (string assemblyFile in assemblyReferences) {
                    rt.Assemblies.Includes.Add(assemblyFile);
                }
            }

            // increment indentation level
            rt.Project.Indent();
            try {
                // execute task
                rt.Execute();
            } finally {
                // restore indentation level
                rt.Project.Unindent();
            }
        }
Пример #2
0
        /// <summary>
        /// Compiles a set of resx files to a .resources files.
        /// </summary>
        /// <param name="resxFiles">The set of resx files to compile.</param>
        protected void CompileResxResources(StringCollection resxFiles) {
            ResGenTask resgen = new ResGenTask();

            // inherit project from current task
            resgen.Project = Project;

            // inherit namespace manager from current task
            resgen.NamespaceManager = NamespaceManager;

            // current task is parent
            resgen.Parent = this;

            // make sure framework specific information is set
            resgen.InitializeTaskConfiguration();
           
            // inherit Verbose setting from current task
            resgen.Verbose = Verbose;

            // set parent of child elements
            resgen.Assemblies.Parent = resgen;

            // inherit project from parent task
            resgen.Assemblies.Project = resgen.Project;

            // inherit namespace manager from parent task
            resgen.Assemblies.NamespaceManager = resgen.NamespaceManager;

            // set base directory for filesets
            resgen.Assemblies.BaseDirectory = References.BaseDirectory;
            resgen.Resources.BaseDirectory = References.BaseDirectory;

            // if resource compiler for current target framework supports external
            // file references, then use source file's directory as current
            // directory for resolving relative file paths
            if (resgen.SupportsExternalFileReferences) {
                resgen.UseSourcePath = true;
            }

            // inherit assembly references from current task
            foreach (string assemblyFile in References.FileNames) {
                resgen.Assemblies.Includes.Add(assemblyFile);
            }

            // set the resx files to compile
            foreach (string resxFile in resxFiles) {
                resgen.Resources.Includes.Add(resxFile);
            }

            // increment indentation level
            Project.Indent();
            try {
                // execute the task
                resgen.Execute();
            } finally {
                // restore indentation level
                Project.Unindent();
            }
        }