Ejemplo n.º 1
0
        void compileSolution()
        {
            //ProjectItem pi = CurrentSolution.SelectedItem;
            Project p = CurrentSolution?.Projects[1];

            if (p == null)
            {
                return;
            }
            p.Compile();
        }
Ejemplo n.º 2
0
        public string Compile()
        {
            if (ParentProject != null)
            {
                ParentProject.Compile();
            }

            CSharpCodeProvider cp         = new CSharpCodeProvider();
            CompilerParameters parameters = new CompilerParameters();

            foreach (ProjectReference pr in flattenNodes.OfType <ProjectReference>())
            {
                Project p = solution.Projects.FirstOrDefault(pp => pp.ProjectGuid == pr.ProjectGUID);
                if (p == null)
                {
                    throw new Exception("referenced project not found");
                }
                parameters.ReferencedAssemblies.Add(p.Compile());
            }

            string outputDir = getDirectoryWithTokens(this.OutputPath);
            string objDir    = getDirectoryWithTokens(this.IntermediateOutputPath);

            Directory.CreateDirectory(outputDir);
            Directory.CreateDirectory(objDir);

            parameters.OutputAssembly = System.IO.Path.Combine(outputDir, this.AssemblyName);

            // True - exe file generation, false - dll file generation
            if (this.OutputType == "Library")
            {
                parameters.GenerateExecutable = false;
                parameters.CompilerOptions   += " /target:library";
                parameters.OutputAssembly    += ".dll";
            }
            else
            {
                parameters.GenerateExecutable = true;
                parameters.CompilerOptions   += " /target:exe";
                parameters.OutputAssembly    += ".exe";
                parameters.MainClass          = this.StartupObject;
            }

            parameters.GenerateInMemory        = false;
            parameters.IncludeDebugInformation = this.DebugSymbols;
            parameters.TreatWarningsAsErrors   = this.TreatWarningsAsErrors;
            parameters.WarningLevel            = this.WarningLevel;
            parameters.CompilerOptions        += " /noconfig";
            if (this.AllowUnsafeBlocks)
            {
                parameters.CompilerOptions += " /unsafe";
            }
            parameters.CompilerOptions += " /delaysign+";
            parameters.CompilerOptions += " /debug:full /debug+";
            parameters.CompilerOptions += " /optimize-";
            parameters.CompilerOptions += " /define:\"DEBUG;TRACE\"";
            parameters.CompilerOptions += " /nostdlib";



            foreach (ProjectItem pi in flattenNodes.Where(p => p.Type == ItemType.Reference))
            {
                if (string.IsNullOrEmpty(pi.HintPath))
                {
                    parameters.CompilerOptions += " /reference:/usr/lib/mono/4.5/" + pi.Path + ".dll";
                    continue;
                }
                parameters.ReferencedAssemblies.Add(pi.Path);
                string fullHintPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(RootDir, pi.HintPath.Replace('\\', '/')));
                if (File.Exists(fullHintPath))
                {
                    string outPath = System.IO.Path.Combine(outputDir, System.IO.Path.GetFileName(fullHintPath));
                    if (!File.Exists(outPath))
                    {
                        File.Copy(fullHintPath, outPath);
                    }
                }
            }
            parameters.CompilerOptions += " /reference:/usr/lib/mono/4.5/System.Core.dll";
            parameters.CompilerOptions += " /reference:/usr/lib/mono/4.5/mscorlib.dll";
            //parameters.ReferencedAssemblies.Add ("System.Core");
            //parameters.ReferencedAssemblies.Add ("mscorlib.dll");


            IEnumerable <ProjectFile> pfs = flattenNodes.OfType <ProjectFile> ();

            foreach (ProjectFile pi in pfs.Where(p => p.Type == ItemType.EmbeddedResource))
            {
                string absPath   = pi.AbsolutePath;
                string logicName = pi.LogicalName;
                if (string.IsNullOrEmpty(logicName))
                {
                    parameters.CompilerOptions += string.Format(" /resource:{0},{1}", absPath, this.Name + "." + pi.Path.Replace('/', '.'));
                }
                else
                {
                    parameters.CompilerOptions += string.Format(" /resource:{0},{1}", absPath, logicName);
                }
            }
            foreach (ProjectFile pi in pfs.Where(p => p.Type == ItemType.None))
            {
                if (pi.CopyToOutputDirectory == CopyToOutputState.Never)
                {
                    continue;
                }
                string source = pi.AbsolutePath;
                string target = System.IO.Path.Combine(outputDir, pi.Path);
                Directory.CreateDirectory(System.IO.Path.GetDirectoryName(target));

                if (File.Exists(target))
                {
                    if (pi.CopyToOutputDirectory == CopyToOutputState.PreserveNewest)
                    {
                        if (DateTime.Compare(
                                System.IO.File.GetLastWriteTime(source),
                                System.IO.File.GetLastWriteTime(target)) < 0)
                        {
                            continue;
                        }
                    }
                    File.Delete(target);
                }
                System.Diagnostics.Debug.WriteLine("copy " + source + " to " + target);
                File.Copy(source, target);
            }
            string[] files = pfs.Where(p => p.Type == ItemType.Compile).Select(p => p.AbsolutePath).ToArray();

            System.Diagnostics.Debug.WriteLine("---- start compilation of :" + parameters.OutputAssembly);
            System.Diagnostics.Debug.WriteLine(parameters.CompilerOptions);

            CompilationResults = cp.CompileAssemblyFromFile(parameters, files);

            solution.UpdateErrorList();

            return(parameters.OutputAssembly);
        }