Пример #1
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) });
            }
        }
Пример #2
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))));
        }