示例#1
0
        private ProjectCompiler RunCode_CompileCode(CompilerProjectReader projectReader, string assemblyFilename, string sourceFile)
        {
            ProjectCompiler compiler = new ProjectCompiler(CompilerManager.Current.Win32ResourceCompiler, CompilerManager.Current.ResourceCompiler);

            //try
            //{
            compiler.SetOutputAssembly(assemblyFilename + ".dll");
            //compiler.AddSource(new CompilerFile(sourceFile));
            compiler.AddSource(new CompilerFile {
                File = sourceFile
            });

            //if (projectReader != null)
            //    compiler.SetProjectCompilerFile(projectReader.GetProjectCompilerFile());

            // CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml
            //compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), runCode: true);
            compiler.SetParameters(projectReader, runCode: true);
            compiler.SetTarget("library");

            CompilerManager.Current.UpdateAssemblies(compiler.Assemblies.Values);
            compiler.Compile();

            return(compiler);
        }
示例#2
0
        //public void CopyProjectSourceFiles(string projectName, string destinationDirectory)
        //{
        //    string pathProject = GetPathProject(projectName);
        //    Trace.WriteLine("Copy project source files \"{0}\" to \"{1}\"", pathProject, destinationDirectory);
        //    Compiler compiler = CreateProjectCompiler(pathProject);
        //    compiler.CopySourceFiles(destinationDirectory.zRootPath(zPath.GetDirectoryName(pathProject)));
        //}

        //public void ZipProjectSourceFiles(string projectName, string zipFile)
        //{
        //    string pathProject = GetPathProject(projectName);
        //    Trace.WriteLine("Zip project source files \"{0}\" to \"{1}\"", pathProject, zipFile);
        //    Compiler compiler = CreateProjectCompiler(pathProject);
        //    compiler.ZipSourceFiles(zipFile.zRootPath(zPath.GetDirectoryName(pathProject)));
        //}

        // not used le 04/12/2016, it is used from runsource to compile a project
        public IProjectCompiler CompileProject(string projectName)
        {
            // - compile assembly project (like runsource.dll.project.xml) and runsource project (like download.project.xml)
            // - for assembly project use CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml
            // - for runsource project use CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml

            //Compiler compiler = new Compiler();
            //projectName = GetProjectVariableValue(projectName, throwError: true);
            //string pathProject = GetFilePath(projectName);
            //compiler.DefaultDir = zPath.GetDirectoryName(pathProject);
            //// CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml
            //compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), dontSetOutput: true);
            //Trace.WriteLine("Compile project \"{0}\"", pathProject);
            //compiler.SetParameters(CompilerProject.Create(new XmlConfig(pathProject).GetConfigElementExplicit("/AssemblyProject")));

            string pathProject = GetPathProject(projectName);

            Trace.WriteLine("Compile project \"{0}\"", pathProject);
            //ProjectCompiler compiler = CreateProjectCompiler(pathProject);
            ProjectCompiler compiler = ProjectCompiler.Create(pathProject, CompilerManager.Current.Win32ResourceCompiler, CompilerManager.Current.ResourceCompiler);

            //compiler.RunsourceSourceDirectory = GetRunSourceConfig().Get("UpdateRunSource/UpdateDirectory").zRootPath(zapp.GetEntryAssemblyDirectory());
            compiler.RunsourceSourceDirectory = GetRunSourceConfig().Get("RunsourceSourceDirectory").zRootPath(zapp.GetEntryAssemblyDirectory());

            compiler.Compile();
            string s = null;

            if (!compiler.Success)
            {
                SetResult(compiler.GetCompilerMessagesDataTable());
                s = " with error(s)";
            }
            else
            {
                // trace warning
                compiler.TraceMessages();
                //if (compiler.CopyRunSourceSourceFiles)
                //{
                //    string runsourceDirectory = GetRunSourceConfig().Get("UpdateRunSource/UpdateDirectory").zRootPath(zapp.GetEntryAssemblyDirectory());
                //    if (runsourceDirectory != null)
                //    {
                //        foreach (string directory in compiler.CopyOutputDirectories)
                //        {
                //            Trace.WriteLine("  copy runsource source files from \"{0}\" to \"{1}\"", runsourceDirectory, directory);
                //            foreach (string file in zDirectory.EnumerateFiles(runsourceDirectory, "*" + ProjectCompiler.ZipSourceFilename))
                //                zfile.CopyFileToDirectory(file, directory, options: CopyFileOptions.OverwriteReadOnly | CopyFileOptions.CopyOnlyIfNewer);
                //        }
                //    }
                //}
            }
            Trace.WriteLine("  compiled{0} : {1}", s, compiler.OutputAssembly);
            return(compiler);
        }
示例#3
0
        public static bool CompileProjects(string projectsFile, Win32ResourceCompiler win32ResourceCompiler, ResourceCompiler resourceCompiler = null, string runsourceSourceDirectory = null, Action <IProjectCompiler> onCompiled = null)
        {
            Chrono chrono = new Chrono();

            chrono.Start();
            int nbProject = 0;

            try
            {
                if (!zFile.Exists(projectsFile))
                {
                    throw new PBException("projects file dont exists \"{0}\"", projectsFile);
                }
                XmlConfig projects          = new XmlConfig(projectsFile);
                string    projectsDirectory = zPath.GetDirectoryName(projectsFile);
                //string updateDir = _config.GetExplicit("UpdateRunSource/UpdateDirectory").zRootPath(zapp.GetEntryAssemblyDirectory());

                string updateDirectory = projects.Get("UpdateDirectory");

                foreach (XElement project in projects.GetElements("Project"))
                {
                    string projectFile = project.zExplicitAttribValue("value").zRootPath(projectsDirectory);
                    Trace.WriteLine("Compile project \"{0}\"", projectFile);

                    ProjectCompiler compiler = ProjectCompiler.Create(projectFile, win32ResourceCompiler, resourceCompiler);
                    compiler.RunsourceSourceDirectory = runsourceSourceDirectory;
                    compiler.Compile();
                    compiler.TraceMessages();

                    //if (onCompiled != null)
                    //    onCompiled(compiler);
                    onCompiled?.Invoke(compiler);
                    if (!compiler.Success)
                    {
                        return(false);
                    }
                    string copyOutput = project.zAttribValue("copyOutput").zRootPath(zapp.GetEntryAssemblyDirectory());
                    if (copyOutput != null)
                    {
                        //Trace.WriteLine("  copy result files to directory \"{0}\"", copyOutput);
                        compiler.CopyResultFilesToDirectory(copyOutput);
                    }
                    if (project.zAttribValue("copyToUpdateDirectory").zTryParseAs(false))
                    {
                        if (updateDirectory == null)
                        {
                            throw new PBException("update directory is not defined");
                        }
                        //Trace.WriteLine("  copy result files to directory \"{0}\"", updateDirectory);
                        compiler.CopyResultFilesToDirectory(updateDirectory);
                    }
                    nbProject++;
                }
            }
            catch (ProjectCompilerException ex)
            {
                Error.WriteMessage(ErrorOptions.TraceError, ex.Message);
            }
            finally
            {
                chrono.Stop();
                Trace.WriteLine("{0} project(s) compiled", nbProject);
                Trace.WriteLine("Process completed {0}", chrono.TotalTimeString);
            }
            return(true);
        }
示例#4
0
        private ProjectCompiler RunCode_CompileCode(CompilerProjectReader compilerProject, string assemblyFilename, string sourceFile)
        {
            ProjectCompiler compiler = new ProjectCompiler(CompilerManager.Current.Win32ResourceCompiler, CompilerManager.Current.ResourceCompiler);

            //try
            //{
            compiler.SetOutputAssembly(assemblyFilename + ".dll");
            compiler.AddSource(new CompilerFile(sourceFile));

            if (compilerProject != null)
                compiler.SetProjectCompilerFile(compilerProject.GetProjectCompilerFile());

            // CompilerDefaultValues from runsource.runsource.config.xml runsource.runsource.config.local.xml
            //compiler.SetParameters(GetRunSourceConfigCompilerDefaultValues(), runCode: true);
            compiler.SetParameters(compilerProject, runCode: true);
            compiler.SetTarget("library");

            CompilerManager.Current.UpdateAssemblies(compiler.Assemblies.Values);
            compiler.Compile();

            return compiler;
        }