Inheritance: NAnt.DotNet.Tasks.CompilerBase
示例#1
0
 private void SetKnownProperties(ProjectRootElement project, CscTask task)
 {
     // MSBuild properties http://msdn.microsoft.com/en-us/library/bb629394.aspx
     // NAnt CscTask properties http://nant.sourceforge.net/nightly/latest/help/tasks/csc.html
     project.SetDefaultPropertyValue("AssemblyName", Path.GetFileNameWithoutExtension(task.OutputFile.Name));
     project.EnsurePropertyExists("ProjectGuid", Guid.NewGuid().ToString("B"));
     if (!String.IsNullOrWhiteSpace(task.BaseAddress))
         project.SetDefaultPropertyValue("BaseAddress", task.BaseAddress);
     project.SetDefaultPropertyValue("CheckForOverflowUnderflow", task.Checked.ToString());
     project.SetDefaultPropertyValue("CodePage", task.Codepage ?? String.Empty);
     project.SetDefaultPropertyValue("DebugSymbols", task.Debug.ToString());
     if (task.DebugOutput == DebugOutput.Enable)
     {
         task.DebugOutput = DebugOutput.Full;
         task.Define = String.Format("DEBUG,TRACE,{0}", task.Define);
     }
     project.SetDefaultPropertyValue("DebugType", task.DebugOutput.ToString());
     if (task.DocFile != null)
         project.SetDefaultPropertyValue("DocumentationFile",
             MB.ProjectCollection.Escape(task.DocFile.GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))));
     if (task.FileAlign > 0)
         project.SetDefaultPropertyValue("FileAlignment", task.FileAlign.ToString(CultureInfo.InvariantCulture));
     // TODO: langversion
     // TODO: noconfig
     // TODO: nostdlib
     project.SetDefaultPropertyValue("Optimize", task.Optimize.ToString());
     project.SetDefaultPropertyValue("Platform", task.Platform ?? "AnyCPU");
     project.SetDefaultPropertyValue("ProjectTypeGuids", projectTypeGuid.ToString("B"));
     project.SetDefaultPropertyValue("AllowUnsafeBlocks", task.Unsafe.ToString());
     project.SetDefaultPropertyValue("WarningLevel", task.WarningLevel ?? "4");
     project.SetDefaultPropertyValue("OutputPath",
         MB.ProjectCollection.Escape(task.OutputFile.Directory.GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))));
     project.SetDefaultPropertyValue("OutputType", task.OutputTarget);
     project.SetDefaultPropertyValue("DefineConstants", task.Define ?? String.Empty);
     // TODO: delaysign
     // TODO: keycontainer
     // TODO: main
     project.SetDefaultPropertyValue("TreatWarningsAsErrors", task.WarnAsError.ToString());
     // TODO: win32icon
     // TODO: win32res
     // TODO: implement the rest of warning-disabling/enabling logic (see CompilerBase.WriteNoWarnList())
     var warnings = new StringBuilder();
     foreach (var warning in task.SuppressWarnings)
         if (warning.IfDefined && !warning.UnlessDefined)
             warnings.AppendFormat("{0},", warning.Number);
     project.SetDefaultPropertyValue("NoWarn", warnings.ToString());
 }
示例#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"];

            // needed because of sqlite3.dll, when compiling on Linux for Windows
            if (this.Project.PlatformName == "unix")
            {
                csc.Platform = "x86";
            }

            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(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();
        }
示例#3
0
        private void GenerateCompileIncludes(ProjectRootElement project, MB.Project projectManipulator, CscTask task)
        {
            projectManipulator.RemoveItems(projectManipulator.GetItemsIgnoringCondition("Compile"));
            projectManipulator.RemoveItems(projectManipulator.GetItemsIgnoringCondition("EmbeddedResource"));

            foreach (var include in task.Sources.FileNames)
            {
                project.AddItem(
                    "Compile",
                    MB.ProjectCollection.Escape(new FileInfo(include).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))),
                    new[]
                    {
                        new KeyValuePair<string, string>("SubType", "Code")
                    });
            }
            foreach (var resourceList in task.ResourcesList)
            {
                foreach (var resource in resourceList.FileNames)
                {
                    project.AddItem(
                        "EmbeddedResource",
                        MB.ProjectCollection.Escape(new FileInfo(resource).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))),
                        new[]
                        {
                            new KeyValuePair<string, string>("LogicalName", resourceList.GetManifestResourceName(resource))
                        });
                }
            }
            project.EnsureItemExists("None", MB.ProjectCollection.Escape(
                new FileInfo(task.Project.BuildFileLocalName).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))));
        }
示例#4
0
        private void GenerateReferences(ProjectRootElement project, MB.Project projectManipulator, CscTask task, GenerateMsBuildTask generator)
        {
            projectManipulator.RemoveItems(projectManipulator.GetItemsIgnoringCondition("Reference"));
            projectManipulator.RemoveItems(projectManipulator.GetItemsIgnoringCondition("ProjectReference"));

            foreach(var reference in task.References.FileNames)
            {
                var name = Path.GetFileNameWithoutExtension(reference);
                var relativeReference = new FileInfo(reference).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath));
                var matchedProject = generator.FindProjectReference(relativeReference);
                if (matchedProject == null)
                {
                    project.AddItem(
                        "Reference",
                        name,
                        new[]
                        {
                            new KeyValuePair<string, string>("Name", name),
                            new KeyValuePair<string, string>("HintPath", MB.ProjectCollection.Escape(relativeReference))
                        });
                }
                else
                {
                    project.AddItem(
                        "ProjectReference",
                        MB.ProjectCollection.Escape(new FileInfo(matchedProject.FullPath).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))),
                        new[]
                        {
                            new KeyValuePair<string, string>("Project", matchedProject.GetProjectId().ToString("B")),
                            new KeyValuePair<string, string>("Name", matchedProject.GetAssemblyName())
                        });
                }
            }
            foreach (var reference in new[] { "mscorlib", "System", "System.Xml" })
            {
                project.AddItem("Reference", reference, new[] { new KeyValuePair<string, string>("Name", reference) });
            }
        }
示例#5
0
        private void PerformDependentResxTests(CscTask cscTask, ResourceFileSet resources)
        {
            // holds the path to the resource file
            string resourceFile = null;

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName,
                "ResourceFile.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine(
                resources.BaseDirectory.FullName, "ResourceFile." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("ResourceTest.HelloWorld.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName,
                "ResourceFile.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCode, Path.Combine(
                resources.BaseDirectory.FullName, "ResourceFile." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("HelloWorld.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName,
                "ResourceFile.en-US.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine(
                resources.BaseDirectory.FullName, "ResourceFile." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("ResourceTest.HelloWorld.en-US.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName,
                "ResourceFile.en-US.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCode, Path.Combine(
                resources.BaseDirectory.FullName, "ResourceFile." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("HelloWorld.en-US.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir"
                + Path.DirectorySeparatorChar + "ResourceFile.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine(
                resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar
                + "ResourceFile." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("ResourceTest.HelloWorld.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir"
                + Path.DirectorySeparatorChar + "ResourceFile.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCode, Path.Combine(
                resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar
                + "ResourceFile." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("HelloWorld.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir"
                + Path.DirectorySeparatorChar + "ResourceFile.en-US.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine(
                resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar
                + "ResourceFile." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("ResourceTest.HelloWorld.en-US.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir"
                + Path.DirectorySeparatorChar + "ResourceFile.en-US.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCode, Path.Combine(
                resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar
                + "ResourceFile." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("HelloWorld.en-US.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir"
                + Path.DirectorySeparatorChar + "ResourceFile.en-US.dunno.en-US.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine(
                resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar
                + "ResourceFile.en-US.dunno." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("ResourceTest.HelloWorld.en-US.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir"
                + Path.DirectorySeparatorChar + "ResourceFile.en-US.dunno.en-US.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // create dependent file
            TempFile.CreateWithContents(_sourceCode, Path.Combine(
                resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar
                + "ResourceFile.en-US.dunno." + cscTask.Extension));
            // assert manifest resource name
            Assert.AreEqual("HelloWorld.en-US.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));
        }
示例#6
0
            /// <summary>
            /// Parses the input, ensuring the class name is found
            /// </summary>
            public void VerifyFindClassname(string input, string expectedClassname)
            {
                CscTask cscTask = new CscTask();
                StringReader reader = new StringReader(input);
                CompilerBase.ResourceLinkage linkage = cscTask.PerformSearchForResourceLinkage( reader );

                Assert.IsNotNull(linkage, "no resourcelinkage found for " + input);
                Assert.AreEqual(expectedClassname, linkage.ClassName);
            }
示例#7
0
        public void Test_ManifestResourceName_Resx_StandAlone_Prefix()
        {
            CscTask cscTask = new CscTask();
            cscTask.Project = CreateEmptyProject();

            ResourceFileSet resources = new ResourceFileSet();
            resources.BaseDirectory = TempDirectory;
            resources.Prefix = "TestNamespace";
            resources.DynamicPrefix = false;

            // holds the path to the resource file
            string resourceFile = null;

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName,
                "ResourceFile.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // assert manifest resource name
            Assert.AreEqual(resources.Prefix + "." + "ResourceFile.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "ResourceFile.en-US.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // assert manifest resource name
            Assert.AreEqual(resources.Prefix + "." + "ResourceFile.en-US.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir"
                + Path.DirectorySeparatorChar + "ResourceFile.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // assert manifest resource name
            Assert.AreEqual(resources.Prefix + "." + "ResourceFile.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir"
                + Path.DirectorySeparatorChar + "ResourceFile.en-US.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // assert manifest resource name
            Assert.AreEqual(resources.Prefix + "." + "ResourceFile.en-US.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));

            // initialize resource file
            resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir"
                + Path.DirectorySeparatorChar + "ResourceFile.en-US.dunno.en-US.resx");
            // create resource file
            CreateTempFile(resourceFile);
            // assert manifest resource name
            Assert.AreEqual(resources.Prefix + "." + "ResourceFile.en-US.dunno.en-US.resources",
                cscTask.GetManifestResourceName(resources, resourceFile));
        }
示例#8
0
        public void Test_ManifestResourceName_Resx_Prefix_DynamicPrefix()
        {
            CscTask cscTask = new CscTask();
            cscTask.Project = CreateEmptyProject();

            ResourceFileSet resources = new ResourceFileSet();
            resources.BaseDirectory = TempDirectory;
            resources.Prefix = "TestNamespace";
            resources.DynamicPrefix = true;

            // prefix should be ignored for resx files
            PerformDependentResxTests(cscTask, resources);
        }
示例#9
0
        public void Test_ManifestResourceName_Resx_DynamicPrefix()
        {
            CscTask cscTask = new CscTask();
            cscTask.Project = CreateEmptyProject();

            ResourceFileSet resources = new ResourceFileSet();
            resources.BaseDirectory = TempDirectory;
            resources.DynamicPrefix = true;

            PerformDependentResxTests(cscTask, resources);
        }
示例#10
0
        public void Test_ManifestResourceName_NonExistingResource()
        {
            CscTask cscTask = new CscTask();
            cscTask.Project = CreateEmptyProject();

            ResourceFileSet resources = new ResourceFileSet();
            resources.BaseDirectory = TempDirectory;
            resources.DynamicPrefix = true;

            cscTask.GetManifestResourceName(resources, "I_dont_exist.txt");
        }
示例#11
0
文件: Resource.cs 项目: RoastBoy/nant
        private string GetManifestResourceNameCSharp(ConfigurationSettings configSetting, string dependentFile) {
            // defer to the resource management code in CscTask
            CscTask csc = new CscTask();
            csc.Project = _solutionTask.Project;
            csc.NamespaceManager = _solutionTask.NamespaceManager;
            csc.OutputFile = new FileInfo(FileUtils.CombinePaths(configSetting.OutputDir.FullName, 
                Project.ProjectSettings.OutputFileName));

            // set-up resource fileset
            ResourceFileSet resources = new ResourceFileSet();
            resources.Project = _solutionTask.Project;
            resources.NamespaceManager = _solutionTask.NamespaceManager;
            resources.Parent = csc;
            resources.BaseDirectory = new DirectoryInfo(Path.GetDirectoryName(Project.ProjectPath));
            resources.Prefix = Project.ProjectSettings.RootNamespace;
            resources.DynamicPrefix = true;

            // bug #1042917: use logical location of resource file to determine
            // manifest resource name
            return csc.GetManifestResourceName(resources, InputFile.FullName,
                LogicalFile.FullName, dependentFile);
        }