예제 #1
0
        private void CompileExe(string code, FileInfo outputFile, string[] resourcePaths)
        {
            FileInfo exeSourceFile = new FileInfo(Path.GetTempFileName() + ".cs");

            using (StreamWriter writer = exeSourceFile.CreateText())
            {
                writer.WriteLine(code);
                writer.Close();
            }

            Log(Level.Debug,
                string.Format("compiling nunit-console at '{0}' to '{1}'", exeSourceFile.FullName,
                              outputFile.FullName));

            CscTask csc = new CscTask();

            csc.Parent           = this;
            csc.Project          = Project;
            csc.NamespaceManager = NamespaceManager;
            csc.InitializeTaskConfiguration();

            csc.OutputFile   = outputFile;
            csc.OutputTarget = "exe";
            csc.Debug        = false;
            csc.Optimize     = true;
            csc.Sources      = new FileSet();
            csc.Sources.Includes.Add(exeSourceFile.FullName);
            csc.References = new AssemblyFileSet();
            csc.References.Includes.Add(ResolveAssemblyLocation("nunit-console-runner", resourcePaths).FullName);
            csc.Execute();
        }
예제 #2
0
        protected void RunCscTask()
        {
            CscTask csc = new CscTask();

            this.CopyTo(csc);

            if (this.Project.PlatformName == "unix")
            {
                // on Windows this is csc, but on Mono on Linux or Mac we need mcs
                csc.ExeName = "mcs";
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(FCSProjFile);

            XmlNode propertyGroup = doc.DocumentElement.FirstChild;
            Dictionary <string, string> mainProperties = new Dictionary <string, string>();

            foreach (XmlNode propNode in propertyGroup.ChildNodes)
            {
                mainProperties.Add(propNode.Name, propNode.InnerText);
            }

            string OutputFile = Path.GetFullPath(Path.GetDirectoryName(FCSProjFile) + "/" + mainProperties["OutputPath"].Replace("\\", "/"));

            OutputFile += "/" + mainProperties["AssemblyName"];

            if (mainProperties["OutputType"].ToLower() == "library")
            {
                OutputFile += ".dll";
            }
            else
            {
                OutputFile += ".exe";
            }

            csc.OutputFile   = new FileInfo(OutputFile);
            csc.DocFile      = new FileInfo(mainProperties["DocumentationFile"]);
            csc.OutputTarget = mainProperties["OutputType"];

            csc.Define = "DEBUGMODE";

            String FrameworkDLLPath = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(System.Type)).Location);

            foreach (XmlNode ProjectNodeChild in doc.DocumentElement)
            {
                if (ProjectNodeChild.Name == "ItemGroup")
                {
                    foreach (XmlNode ItemNode in ProjectNodeChild)
                    {
                        if (ItemNode.Name == "Reference")
                        {
                            if (ItemNode.HasChildNodes && (ItemNode.ChildNodes[0].Name == "HintPath"))
                            {
                                csc.References.AsIs.Add(ItemNode.ChildNodes[0].InnerText);
                            }
                            else
                            {
                                // .net dlls
                                csc.References.AsIs.Add(
                                    FrameworkDLLPath + Path.DirectorySeparatorChar +
                                    ItemNode.Attributes["Include"].Value + ".dll");
                            }
                        }
                        else if (ItemNode.Name == "ProjectReference")
                        {
                            string ReferencedProjectName = ItemNode.ChildNodes[1].InnerText;
                            csc.References.AsIs.Add(
                                Path.GetDirectoryName(OutputFile) + Path.DirectorySeparatorChar +
                                ReferencedProjectName + ".dll");
                        }
                        else if (ItemNode.Name == "Compile")
                        {
                            csc.Sources.AsIs.Add(Path.GetDirectoryName(FCSProjFile) + Path.DirectorySeparatorChar +
                                                 ItemNode.Attributes["Include"].Value);
                        }
                        else if (ItemNode.Name == "EmbeddedResource")
                        {
                            ResourceFileSet fs = new ResourceFileSet();
                            fs.AsIs.Add(ItemNode.Attributes["Include"].Value);
                            csc.ResourcesList.Add(fs);
                        }
                    }
                }
            }

            csc.Execute();
        }