예제 #1
0
        private CompilerFile CreateCompilerFile(XElement xe, CompilerProjectReader project = null)
        //private CompilerFile CreateCompilerFile(XElement xe, string projectFile)
        {
            if (xe == null)
            {
                return(null);
            }
            //if (project == null)
            //    project = this;
            //CompilerFile compilerFile = new CompilerFile(GetPathFile(xe.Attribute("value").Value), GetRootDirectory());
            //CompilerFile compilerFile = new CompilerFile(project.GetPathFile(xe.Attribute("value").Value), project.GetRootDirectory());
            CompilerFile compilerFile = new CompilerFile {
                File = project.GetPathFile(xe.Attribute("value").Value), ProjectFile = project._projectFile
            };

            //CompilerFile compilerFile = new CompilerFile { File = xe.Attribute("value").Value.zRootPath(zPath.GetDirectoryName(projectFile)), ProjectFile = projectFile };
            //compilerFile.Project = project;
            //compilerFile.ProjectFile = project._projectFile;
            foreach (XAttribute xa in xe.Attributes())
            {
                if (xa.Name != "value")
                {
                    compilerFile.Attributes.Add(xa.Name.LocalName, xa.Value);
                }
            }
            return(compilerFile);
        }
예제 #2
0
        public string CompileResource(CompilerFile resource, string outputDir)
        {
            // Utilisation de Resgen.exe http://msdn.microsoft.com/fr-fr/library/ccec7sz1.aspx
            // resgen [parameters] [/compile]filename.extension [outputFilename.extension] [/str:lang[,namespace[,class[,file]]]]

            //   /compile
            //      Permet de spécifier plusieurs fichiers .resx ou texte à convertir en plusieurs fichiers .resources en une seule opération globale.
            //      Si vous omettez cette option, vous ne pouvez spécifier qu'un seul argument de fichier d'entrée.
            //      Cette option ne peut pas être utilisée avec l'option /str:.
            //   /publicClass
            //      Crée un type de ressources fortement typé comme classe public.
            //      Cette option est ignorée si l'option /str: n'est pas utilisée.
            //   /r:assembly
            //      Spécifie que les types doivent être chargés à partir d'un assembly.
            //      Si vous spécifiez cette option, un fichier .resx avec une version antérieure d'un type utilisera le type dans un assembly.
            //   /str:language[,namespace[,classname[,filename]]]
            //      Crée un fichier de classe de ressources fortement typé dans le langage de programmation (cs ou C# pour C#, vb ou visualbasic pour Visual Basic)
            //      spécifié dans l'option language.
            //      Vous pouvez utiliser l'option namespace pour spécifier l'espace de noms par défaut du projet,
            //      l'option classname pour spécifier le nom de la classe générée et l'option filename pour spécifier le nom du fichier de classe.
            //      Remarque	Dans le .NET Framework version 2.0, classname et filename sont ignorés si namespace n'est pas spécifié. 
            //      Un seul fichier d'entrée est autorisé lorsque l'option /str: est utilisée, afin qu'il ne puisse pas être utilisé avec l'option /compile.
            //      Si namespace est spécifié mais que classname ne l'est pas, le nom de la classe est dérivé du nom de fichier de sortie
            //      (par exemple, les traits de soulignement sont substitués pour les périodes).Les ressources fortement typées peuvent ne pas fonctionner correctement en conséquence.Pour éviter ce problème, spécifiez à la fois le nom de la classe et le nom du fichier de sortie.
            //   /usesourcepath
            //      Précise que le répertoire actif du fichier d'entrée sera utilisé pour résoudre des chemins d'accès de fichier relatif.
            //
            //  commande utilisée :
            //    Resgen.exe resource.resx resource.resources /str:cs,PibLink,PibLink_resource
            //    Resgen.exe PibLink_resource.resx WRunSource.Class.PibLink.PibLink_resource.resources /str:cs,WRunSource.Class.PibLink,PibLink_resource



            // accès au paramètres de compilation des ressources d'un projet
            // namespace : Microsoft.VisualStudio.VCProjectEngine
            // class : VCManagedResourceCompilerTool
            //string sPathCompiledResource = cu.PathSetDir(cu.PathSetExt(resource, ".resources"), outputDir);

            if (!zDirectory.Exists(outputDir))
                zDirectory.CreateDirectory(outputDir);

            string resourceFile = resource.File;
            string resourceFilename = zPath.GetFileNameWithoutExtension(resourceFile);
            string nameSpace = null;
            //int i = resource.Attributes.IndexOfKey("namespace");
            //if (i != -1) nameSpace = resource.Attributes.Values[i];
            if (resource.Attributes.ContainsKey("namespace"))
                nameSpace = resource.Attributes["namespace"];
            string sPathCompiledResource = resourceFilename + ".resources";
            if (nameSpace != null)
                sPathCompiledResource = nameSpace + "." + sPathCompiledResource;
            //"WRunSource.Class.PibLink."
            sPathCompiledResource = zpath.PathSetDirectory(sPathCompiledResource, outputDir);
            if (zFile.Exists(sPathCompiledResource) && zFile.Exists(resourceFile))
            {
                //FileInfo fiResource = new FileInfo(resourceFile);
                var fiResource = zFile.CreateFileInfo(resourceFile);
                //FileInfo fiCompiledResource = new FileInfo(sPathCompiledResource);
                var fiCompiledResource = zFile.CreateFileInfo(sPathCompiledResource);
                if (fiCompiledResource.LastWriteTime > fiResource.LastWriteTime)
                    return sPathCompiledResource;
            }
            if (_resourceCompiler == null)
                throw new PBException("error resource compiler is not defined");
            if (!zFile.Exists(_resourceCompiler))
                throw new PBException("error resource compiler cannot be found {0}", _resourceCompiler);
            ProcessStartInfo pi = new ProcessStartInfo();
            pi.FileName = _resourceCompiler;
            //pi.Arguments = cu.PathGetFileWithExt(resource);
            //pi.Arguments = resource + " " + sPathCompiledResource;
            //    Resgen.exe PibLink_resource.resx PibLink.PibLink_resource.resources /str:cs,PibLink,PibLink_resource
            //pi.Arguments = resource + " " + sPathCompiledResource + " /str:cs";
            pi.Arguments = resourceFile + " " + sPathCompiledResource;
            if (nameSpace != null) pi.Arguments += " /str:cs," + nameSpace + "," + resourceFilename;
            //cTrace.Trace("{0} {1}", gsResourceCompiler, pi.Arguments);
            WriteLine(1, "  {0} {1}", _resourceCompiler, pi.Arguments);
            //pi.WorkingDirectory = cu.PathGetDir(resource);
            //pi.WorkingDirectory = outputDir;
            pi.UseShellExecute = false;
            pi.RedirectStandardError = true;
            //pi.WorkingDirectory = gsDefaultDir;
            pi.WorkingDirectory = zPath.GetDirectoryName(resourceFile);

            Process p = new Process();
            p.StartInfo = pi;
            gsResourceCompiling = resourceFile;
            p.ErrorDataReceived += new DataReceivedEventHandler(CompileResource_EventErrorDataReceived);
            p.Start();
            p.BeginErrorReadLine();
            while (!p.HasExited)
            {
            }
            if (p.ExitCode != 0)
            {
                _resourceResults.Errors.Add(new ResourceCompilerError(resourceFile, string.Format("error compiling resource, exit code {0}", p.ExitCode)));
                _resourceResults.HasError = true;
            }
            return sPathCompiledResource;
        }
예제 #3
0
        //private void CopyCompileFilesToDirectory(string directory = null)
        //{
        //    CopyAssembliesToDirectory(directory);
        //    CopyFilesToDirectory(directory);
        //}

        //private void CopyFileToOutputDir()
        // List<string>
        // copy files and config file to directory
        //private void CopyFilesToDirectory(string directory = null)
        //{
        //    //List<string> copiedFiles = new List<string>();

        //    if (gResults.PathToAssembly != null)
        //    {
        //        //string sOutputDir = zpath.PathGetDirectory(gResults.PathToAssembly);

        //        if (directory == null)
        //            directory = zpath.PathGetDirectory(gResults.PathToAssembly);

        //        foreach (CompilerFile file in gFileList)
        //        {
        //            string destinationFile = null;
        //            if (file.Attributes.ContainsKey("destinationFile"))
        //            {
        //                destinationFile = file.Attributes["destinationFile"];
        //                WriteLine(2, "  Copy file \"{0}\" to \"{1}\" as \"{2}\"", file.File, directory, destinationFile);
        //            }
        //            else
        //                WriteLine(2, "  Copy file \"{0}\" to \"{1}\"", file.File, directory);
        //            //string path = zfile.CopyFileToDirectory(file.File, directory, destinationFile, true);
        //            string path = zfile.CopyFileToDirectory(file.File, directory, destinationFile, CopyFileOptions.OverwriteReadOnly | CopyFileOptions.CopyOnlyIfNewer);
        //            //if (path != null)
        //            //    copiedFiles.Add(path);
        //        }

        //        if (_appConfig != null)
        //        {
        //            string appFile = zPath.GetFileName(gResults.PathToAssembly) + ".config";
        //            WriteLine(2, "Copy file \"{0}\" to \"{1}\" as \"{2}\"", _appConfig.File, directory, appFile);
        //            //string path = zfile.CopyFileToDirectory(_appConfig.File, directory, appFile, true);
        //            string path = zfile.CopyFileToDirectory(_appConfig.File, directory, appFile, CopyFileOptions.OverwriteReadOnly | CopyFileOptions.CopyOnlyIfNewer);
        //            //if (path != null)
        //            //    copiedFiles.Add(path);
        //        }
        //    }

        //    //return copiedFiles;
        //}

        //private void CopyOutputToDirectories()
        //{
        //    foreach (CopyOutputDirectory cod in _copyOutputDirectories)
        //    {
        //        List<string> copiedFiles = CopyOutputToDirectory(cod);
        //        _copyOutputFiles.Add(new KeyValuePair<string, List<string>>(cod.Directory, copiedFiles));
        //    }
        //}

        //private void CopyOutputToDirectory(CopyOutputDirectory cod, List<string> files)
        //private List<string> CopyOutputToDirectory(CopyOutputDirectory cod)
        //{
        //    List<string> copiedFiles = new List<string>();

        //    if (gResults.PathToAssembly != null)
        //    {
        //        string outputDir = zpath.PathGetDirectory(gResults.PathToAssembly);

        //        WriteLine(1, "Copy output to \"{0}\"", cod.Directory);
        //        if (!Directory.Exists(cod.Directory))
        //            Directory.CreateDirectory(cod.Directory);

        //        // copy assembly
        //        string path = gResults.PathToAssembly;
        //        WriteLine(2, "  Copy file \"{0}\" to \"{1}\"", path, cod.Directory);
        //        //string path3 = zfile.CopyFileToDirectory(path, cod.Directory, null, true);
        //        string path3 = zfile.CopyFileToDirectory(path, cod.Directory, options: CopyFileOptions.OverwriteReadOnly | CopyFileOptions.CopyOnlyIfNewer);

        //        /* Unmerged change from project 'runsource.v2.dll'
        //        Before:
        //                        if (path3 != null)
        //                            copiedFiles.Add(path3);

        //                        // copy assembly pdb
        //                        string path2 = zpath.PathSetExtension(path, ".pdb");
        //                        WriteLine(2, "  Copy file \"{0}\" to \"{1}\"", path2, cod.Directory);
        //                        path3 = zfile.CopyFile(path2, cod.Directory, null, true);
        //                        if (path3 != null)
        //        After:
        //                        if (path3 != null)
        //        */
        //        if (path3 != null)
        //            copiedFiles.Add(path3);

        //        // copy assembly pdb
        //        string path2 = zpath.PathSetExtension(path, ".pdb");
        //        WriteLine(2, "  Copy file \"{0}\" to \"{1}\"", path2, cod.Directory);
        //        //path3 = zfile.CopyFileToDirectory(path2, cod.Directory, null, true);
        //        path3 = zfile.CopyFileToDirectory(path2, cod.Directory, options: CopyFileOptions.OverwriteReadOnly | CopyFileOptions.CopyOnlyIfNewer);
        //        if (path3 != null)
        //            copiedFiles.Add(path3);

        //        // copy assembly pdb
        //        //string path2 = zpath.PathSetExtension(path, ".pdb");
        //        //WriteLine(2, "  Copy file \"{0}\" to \"{1}\"", path2, cod.Directory);
        //        ////path3 = zfile.CopyFileToDirectory(path2, cod.Directory, null, true);
        //        //path3 = zfile.CopyFileToDirectory(path2, cod.Directory, options: CopyFileOptions.OverwriteReadOnly | CopyFileOptions.CopyOnlyIfNewer);
        //        //if (path3 != null)
        //        //    copiedFiles.Add(path3);

        //        // copy assembly config
        //        path2 = path + ".config";
        //        WriteLine(2, "  Copy file \"{0}\" to \"{1}\"", path2, cod.Directory);
        //        //path3 = zfile.CopyFileToDirectory(path2, cod.Directory, null, true);
        //        path3 = zfile.CopyFileToDirectory(path2, cod.Directory, options: CopyFileOptions.OverwriteReadOnly | CopyFileOptions.CopyOnlyIfNewer);
        //        if (path3 != null)
        //            copiedFiles.Add(path3);

        //        // copy referenced assemblies
        //        //foreach (CompilerAssembly ca in gAssemblyList.Values)
        //        //{
        //        //    string assembly = ca.File;
        //        //    if (!File.Exists(assembly)) continue;
        //        //    string assembly2 = zpath.PathSetDirectory(assembly, cod.Directory);
        //        //    if (File.Exists(assembly2))
        //        //    {
        //        //        FileInfo fi1 = new FileInfo(assembly);
        //        //        FileInfo fi2 = new FileInfo(assembly2);
        //        //        if (fi1.LastWriteTime <= fi2.LastWriteTime) continue;
        //        //    }
        //        //    WriteLine(2, "  Copy assembly \"{0}\" to \"{1}\"", assembly, assembly2);
        //        //    File.Copy(assembly, assembly2, true);
        //        //    files.Add(assembly2);
        //        //    path = zpath.PathSetExtension(assembly, ".pdb");
        //        //    assembly2 = zpath.PathSetExtension(assembly2, ".pdb");
        //        //    if (File.Exists(path))
        //        //    {
        //        //        WriteLine(2, "  Copy assembly \"{0}\" to \"{1}\"", path, assembly2);
        //        //        File.Copy(path, assembly2, true);
        //        //        files.Add(assembly2);
        //        //    }
        //        //}
        //        List<string> copiedFiles2 = CopyReferencedAssembliesToDirectory(cod.Directory);
        //        copiedFiles.AddRange(copiedFiles2);

        //        // copy files and config file to directory
        //        copiedFiles2 = CopyFilesToDirectory(cod.Directory);
        //        copiedFiles.AddRange(copiedFiles2);

        //        // copy files
        //        foreach (CompilerFile file in cod.Files)
        //        {
        //            path = file.File;
        //            if (!zPath.IsPathRooted(path))
        //                path = zPath.Combine(outputDir, path);
        //            string destinationFile = null;
        //            if (file.Attributes.ContainsKey("destinationFile"))
        //            {
        //                destinationFile = file.Attributes["destinationFile"];
        //                WriteLine(2, "  Copy file \"{0}\" to \"{1}\" as \"{2}\"", path, cod.Directory, destinationFile);
        //            }
        //            else
        //                WriteLine(2, "  Copy file \"{0}\" to \"{1}\"", path, cod.Directory);
        //            //path3 = zfile.CopyFileToDirectory(path, cod.Directory, destinationFile, true);
        //            path3 = zfile.CopyFileToDirectory(path, cod.Directory, destinationFile, CopyFileOptions.OverwriteReadOnly | CopyFileOptions.CopyOnlyIfNewer);
        //            if (path3 != null)
        //                copiedFiles.Add(path3);
        //        }
        //    }
        //    return copiedFiles;
        //}

        public string[] CompileResources(CompilerFile[] resources)
        {
            string outputDir = zPath.Combine(_finalOutputDir, _CompileResourceSubDirectory);
            string[] compiledResources = new string[resources.Length];
            int i = 0;
            foreach (CompilerFile resource in resources)
            {
                compiledResources[i++] = CompileResource(resource, outputDir);
            }
            return compiledResources;
        }
예제 #4
0
        //public void AddCopyOutputDirectories(IEnumerable<XElement> elements)
        //{
        //    foreach (XElement element in elements)
        //    {
        //        CopyOutputDirectory cod = new CopyOutputDirectory();
        //        cod.Directory = zpath.PathMakeRooted(element.zAttribValue("value"), gsDefaultDir);
        //        AddFiles(cod.Files, element.zXPathElements("File"), gsDefaultDir);
        //        _copyOutputDirectories.Add(cod);
        //    }
        //}

        //public void CloseProcess()
        //{
        //    SetFinalOutputAssembly();
        //    if (_finalOutputAssembly == null) return;
        //    string processName = zpath.PathGetFileName(_finalOutputAssembly);
        //    foreach (Process process in Process.GetProcessesByName(processName))
        //    {
        //        if (string.Compare(process.MainModule.FileName, _finalOutputAssembly, true) != 0) continue;
        //        zprocess.CloseProcess(process);
        //    }
        //}

        public void Compile()
        {
            if (!_generateInMemory && _outputAssembly == null)
                throw new PBException("output assembly is not defined");
            SetFinalOutputAssembly();
            if (_finalOutputDir != null)
                zDirectory.CreateDirectory(_finalOutputDir);
            //WriteLine(1, "Compile \"{0}\"", gsFinalOutputAssembly);
            //_defaultDir
            ////WriteLine(1, "Compiler _defaultDir \"{0}\"", _defaultDir);
            WriteLine(2, "Compile \"{0}\"", _finalOutputAssembly);
            WriteLine(2, "  DebugInformation      {0}", _debugInformation);
            WriteLine(2, "  GenerateInMemory      {0}", _generateInMemory);
            WriteLine(2, "  GenerateExecutable    {0}", _generateExecutable);
            WriteLine(2, "  WarningLevel          {0}", _warningLevel);
            WriteLine(2, "  CompilerOptions       \"{0}\"", _compilerOptions);

            _appConfig = GetCompilerFileName("app.config");
            if (_appConfig != null)
                WriteLine(2, "  app.config            \"{0}\"", _appConfig.File);

            CompilerParameters options = new CompilerParameters();
            options.CompilerOptions = _compilerOptions;
            options.GenerateInMemory = _generateInMemory;
            options.OutputAssembly = _finalOutputAssembly;
            options.GenerateExecutable = _generateExecutable;
            options.IncludeDebugInformation = _debugInformation;
            // WarningLevel : from http://msdn.microsoft.com/en-us/library/13b90fz7.aspx
            //   0 Turns off emission of all warning messages.
            //   1 Displays severe warning messages.
            //   2 Displays level 1 warnings plus certain, less-severe warnings, such as warnings about hiding class members.
            //   3 Displays level 2 warnings plus certain, less-severe warnings, such as warnings about expressions that always evaluate to true or false.
            //   4 (the default) Displays all level 3 warnings plus informational warnings.
            options.WarningLevel = _warningLevel;
            //foreach (string s in gAssemblyList.Values)
            foreach (CompilerAssembly assembly in _assemblyList.Values)
            {
                WriteLine(2, "  Assembly              \"{0}\" resolve {1}", assembly.File, assembly.Resolve);
                options.ReferencedAssemblies.Add(assembly.File);
                if (assembly.Resolve)
                    AssemblyResolve.Add(assembly.File, assembly.ResolveName);
            }
            CompilerFile[] resources = GetCompilerFilesType(".resx");
            //string[] compiledResources = CompileResources(resources, gsFinalOutputDir);
            string[] compiledResources = CompileResources(resources);
            foreach (string compiledResource in compiledResources)
            {
                WriteLine(2, "  Resource              \"{0}\"", compiledResource);
                options.EmbeddedResources.Add(compiledResource);
            }

            WriteLine(2, "  Resource error        {0}", _resourceResults.Errors.Count);
            if (_resourceResults.HasError) return;

            //CSharpCodeProvider provider = new CSharpCodeProvider(gProviderOption);
            CodeDomProvider provider = null;
            string sourceExt = null;
            //gLanguage  CSharp, JScript
            if (_language == null)
                throw new PBException("error undefined language");
            string language = _language.ToLower();
            if (language == "csharp")
            {
                provider = new CSharpCodeProvider(_providerOption);
                sourceExt = ".cs";
            }
            else if (language == "jscript")
            {
                provider = new JScriptCodeProvider();
                sourceExt = ".js";
            }
            else
                throw new PBException("error unknow language \"{0}\"", _language);
            //string[] sSources = GetFilesType(".cs");
            string[] sSources = GetFilesType(sourceExt);
            //string currentDirectory = zDirectory.GetCurrentDirectory();
            //Directory.SetCurrentDirectory(zapp.GetAppDirectory());
            //cTrace.Trace("Compiler.Compile() : change current directory to {0}", cu.GetAppDirectory());
            _results = provider.CompileAssemblyFromFile(options, sSources);
            WriteLine(2, "  Compile error warning {0}", _results.Errors.Count);
            WriteLine(2, "  Compile has error     {0}", _results.Errors.HasErrors);
            WriteLine(2, "  Compile has warning   {0}", _results.Errors.HasWarnings);
            //Directory.SetCurrentDirectory(currentDirectory);
            //cTrace.Trace("Compiler.Compile() : restore current directory to {0}", currentDirectory);
            provider.Dispose();

            //CopyAssemblyToOutputDir();
            //if (gResults.PathToAssembly != null && !gbGenerateInMemory)
            //{
            //    List<string> copiedFiles = CopyReferencedAssembliesToDirectory(zpath.PathGetDirectory(gResults.PathToAssembly));
            //    _outputFiles.AddRange(copiedFiles);
            //}

            //CopyFileToOutputDir();
            //if (gResults.PathToAssembly != null)
            //{
            //    List<string> copiedFiles = CopyFilesToDirectory(zpath.PathGetDirectory(gResults.PathToAssembly));
            //    _outputFiles.AddRange(copiedFiles);
            //}

            if (_results.PathToAssembly != null)
                CopyResultFilesToDirectory();

            CopyOutputToDirectories();
        }
예제 #5
0
 public void AddSource(CompilerFile source)
 {
     if (!_sourceList.ContainsKey(source.File))
         _sourceList.Add(source.File, source);
     else
     {
         WriteLine(1, "Compiler warning : duplicate source file \"{0}\" from project \"{1}\"", source.File, source.Project.ProjectFile);
         WriteLine(1, "  already loaded from project \"{0}\"", _sourceList[source.File].Project.ProjectFile);
     }
 }
예제 #6
0
        //public void AddUpdateDirectory(IEnumerable<CompilerUpdateDirectory> updateDirectories)
        //{
        //    _updateDirectories.AddRange(updateDirectories);
        //}

        public void Compile()
        {
            if (!_generateInMemory && _outputAssembly == null)
                throw new PBException("output assembly is not defined");
            SetFinalOutputAssembly();
            if (_finalOutputDir != null)
                zDirectory.CreateDirectory(_finalOutputDir);
            WriteLine(2, "Compile \"{0}\"", _finalOutputAssembly);

            WriteLine(2, $"  Language              {(_language != null ? _language.Name : "-undefined-")} version {(_language != null ? _language.Version : "-undefined-")}");
            if (_frameworkVersion != null)
                WriteLine(2, $"  FrameworkVersion      {_frameworkVersion}");
            WriteLine(2, $"  Target                \"{_target}\"");
            WriteLine(2, $"  Platform              {(_platform ?? "default")}");
            WriteLine(2, $"  OutputAssembly        \"{_outputAssembly}\"");
            WriteLine(2, $"  DebugInformation      {_debugInformation}");
            WriteLine(2, $"  GenerateInMemory      {_generateInMemory}");
            //WriteLine(2, $"  GenerateExecutable    {_generateExecutable}");
            WriteLine(2, $"  WarningLevel          {_warningLevel}");
            WriteLine(2, $"  CompilerOptions       \"{_compilerOptions}\"");
            if (_preprocessorSymbols != null)
                WriteLine(2, $"  PreprocessorSymbols   {_preprocessorSymbols.Values.zToStringValues()}");

            _appConfig = GetCompilerFileName("app.config");
            if (_appConfig != null)
                WriteLine(2, $"  app.config            \"{_appConfig.File}\"");

            //CompilerParameters options = new CompilerParameters();
            //options.CompilerOptions = _compilerOptions;
            //options.GenerateInMemory = _generateInMemory;
            //options.OutputAssembly = _finalOutputAssembly;
            //options.GenerateExecutable = _generateExecutable;
            //options.IncludeDebugInformation = _debugInformation;
            //// WarningLevel : from http://msdn.microsoft.com/en-us/library/13b90fz7.aspx
            ////   0 Turns off emission of all warning messages.
            ////   1 Displays severe warning messages.
            ////   2 Displays level 1 warnings plus certain, less-severe warnings, such as warnings about hiding class members.
            ////   3 Displays level 2 warnings plus certain, less-severe warnings, such as warnings about expressions that always evaluate to true or false.
            ////   4 (the default) Displays all level 3 warnings plus informational warnings.
            //options.WarningLevel = _warningLevel;
            //foreach (CompilerAssembly assembly in _assemblyList.Values)
            //{
            //    //WriteLine(2, "  Assembly              \"{0}\" resolve {1}", assembly.File, assembly.Resolve);
            //    options.ReferencedAssemblies.Add(assembly.File);
            //    // transfered to RunSource.RunCode_ExecuteCode()
            //    //if (assembly.Resolve)
            //    //    AssemblyResolve.Add(assembly.File, assembly.ResolveName);
            //}


            //CompilerFile[] resources = GetCompilerFilesType(".resx");
            //string[] compiledResources = CompileResources(resources);
            //foreach (string compiledResource in compiledResources)
            //{
            //    WriteLine(2, "  Resource              \"{0}\"", compiledResource);
            //    options.EmbeddedResources.Add(compiledResource);
            //}

            //WriteLine(2, "  Resource error        {0}", _resourceResults.Errors.Count);
            //if (_resourceResults.HasError)
            //    return;

            //CodeDomProvider provider = null;
            //string sourceExt = null;
            //// _language : CSharp, JScript
            //if (_language == null)
            //    throw new CompilerException("error undefined language");
            //string language = _language.ToLower();
            //if (language == "csharp")
            //{
            //    provider = new CSharpCodeProvider(_providerOption);
            //    sourceExt = ".cs";
            //}
            //else if (language == "jscript")
            //{
            //    provider = new JScriptCodeProvider();
            //    sourceExt = ".js";
            //}
            //else
            //    throw new CompilerException("error unknow language \"{0}\"", _language);
            //string[] sources = GetFilesType(sourceExt);
            //_results = provider.CompileAssemblyFromFile(options, sources);
            //WriteLine(2, "  Compile error warning {0}", _results.Errors.Count);
            //WriteLine(2, "  Compile has error     {0}", _results.Errors.HasErrors);
            //WriteLine(2, "  Compile has warning   {0}", _results.Errors.HasWarnings);
            //provider.Dispose();

            //ICompiler compiler = GetCompiler(_language);
            if (_language == null)
                throw new PBException("language not defined");
            ICompiler compiler = CompilerManager.Current.GetCompiler(_language.Name);
            compiler.LanguageVersion = _language.Version;
            compiler.FrameworkVersion = _frameworkVersion;
            compiler.Target = _target;
            compiler.Platform = _platform;
            compiler.GenerateInMemory = _generateInMemory;
            compiler.DebugInformation = _debugInformation;
            compiler.WarningLevel = _warningLevel;
            compiler.CompilerOptions = _compilerOptions;
            compiler.SetPreprocessorSymbols(_preprocessorSymbols.Values);
            compiler.OutputAssembly = _finalOutputAssembly;

            // compile win32 resource file
            if (_win32ResourceFile != null)
            {
                string win32CompiledResourceFile = CompileWin32Resource(_win32ResourceFile.File);
                if (_resourceError)
                    return;
                compiler.Win32ResourceFile = win32CompiledResourceFile;
                //if (win32CompiledResourceFile != null)
                //WriteLine(2, "  win32 resource file   \"{0}\"", win32CompiledResourceFile);
                WriteLine(2, $"  win32 resource file   \"{_win32ResourceFile.File}\"");
            }

            //compiler.ProviderOption = _providerOption;
            //compiler.GenerateExecutable = _generateExecutable;

            //compiler.AddSources(GetFilesByType(GetSourceExtension(_language.Name)));
            compiler.SetSources(GetFilesByType(GetSourceExtension(_language.Name)));

            //foreach (CompilerAssembly assembly in _assemblyList.Values)
            //{
            //    WriteLine(2, "  Assembly              \"{0}\" resolve {1}", assembly.File, assembly.Resolve);
            //    compiler.AddReferencedAssembly(assembly.File);
            //}
            compiler.SetReferencedAssemblies(GetReferencedAssemblies());

            // compile resources files
            CompilerFile[] resources = GetCompilerFilesType(".resx");
            ResourceFile[] compiledResources = CompileResources(resources);
            compiler.SetEmbeddedResources(GetCompiledResources(compiledResources));
            WriteLine(2, "  Resource messages     {0}", _resourceMessages.Count);
            if (_resourceError)
                return;

            _result = compiler.Compile();

            WriteLine(2, "  Compile message       {0}", _result.MessagesCount);
            WriteLine(2, "  Compile success       {0}", _result.Success);
            //WriteLine(2, "  Compile has warning   {0}", _result.HasWarnings());


            if (_copySourceFiles)
                CopySourceFiles();

            //if (_results.PathToAssembly != null)
            if (_result.GetAssemblyFile() != null)
                CopyResultFilesToDirectory();

            CopyOutputToDirectories();
            _CopyRunSourceSourceFiles();
        }
예제 #7
0
        public ResourceFile CompileResource(CompilerFile resource, string outputDir)
        {
            string nameSpace = null;
            if (resource.Attributes.ContainsKey("namespace"))
                nameSpace = resource.Attributes["namespace"];
            ResourceFile resourceFile = new ResourceFile { File = resource.File, Namespace = nameSpace };

            ResourceCompilerResult result = _resourceCompiler.Compile(resourceFile, outputDir);
            if (!result.Success)
                _resourceError = true;
            foreach (ResourceCompilerMessage message in result.Messages)
                _resourceMessages.Add(message);
            resourceFile.File = result.CompiledResourceFile;
            return resourceFile;
        }
예제 #8
0
 public void AddSource(CompilerFile source)
 {
     if (!zFile.Exists(source.File))
         throw new ProjectCompilerException($"source file not found \"{source.File}\"");
     if (!_sourceList.ContainsKey(source.File))
         _sourceList.Add(source.File, source);
     else if (_traceDuplicateSource)
     {
         WriteLine(1, $"Compiler warning : duplicate source file \"{source.File}\"");
         WriteLine(1, $"                              in project \"{source.Project.ProjectFile}\"");
         WriteLine(1, $"               already loaded in project \"{_sourceList[source.File].Project.ProjectFile}\"");
     }
 }
예제 #9
0
        //public void SetProviderOptions(IEnumerable<CompilerProviderOption> options, ICompilerProjectReader project = null)
        //{
        //    foreach (CompilerProviderOption option in options)
        //    {
        //        if (_providerOption.ContainsKey(option.Name))
        //        {
        //            WriteLine(1, "Compiler warning : redefine provider option \"{0}\" value \"{1}\" as \"{2}\" from project \"{3}\"", option.Name, _providerOption[option.Name], option.Value, project != null ? project.ProjectFile : "--no project--");
        //            _providerOption.Remove(option.Name);
        //        }
        //        _providerOption.Add(option.Name, option.Value);
        //    }
        //}

        //public void SetWin32Resource(string win32ResourceFile)
        public void SetWin32Resource(CompilerFile win32ResourceFile)
        {
            _win32ResourceFile = win32ResourceFile;
        }
예제 #10
0
 public void SetProjectCompilerFile(CompilerFile projectCompilerFile)
 {
     _projectCompilerFile = projectCompilerFile;
     _projectDirectory = zPath.GetDirectoryName(projectCompilerFile.File);
 }
예제 #11
0
 private CompilerFile CreateCompilerFile(XElement xe)
 {
     if (xe == null)
         return null;
     CompilerFile compilerFile = new CompilerFile(GetPathFile(xe.Attribute("value").Value), GetRootDirectory());
     compilerFile.Project = this;
     foreach (XAttribute xa in xe.Attributes())
     {
         if (xa.Name != "value")
             compilerFile.Attributes.Add(xa.Name.LocalName, xa.Value);
     }
     return compilerFile;
 }
예제 #12
0
 public CompilerFile GetProjectCompilerFile()
 {
     CompilerFile compilerFile = new CompilerFile(_projectFile, GetRootDirectory());
     compilerFile.Project = this;
     return compilerFile;
 }