当前位置: 首页>>代码示例>>C#>>正文


C# Project.GetItems方法代码示例

本文整理汇总了C#中Microsoft.Build.Evaluation.Project.GetItems方法的典型用法代码示例。如果您正苦于以下问题:C# Project.GetItems方法的具体用法?C# Project.GetItems怎么用?C# Project.GetItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Build.Evaluation.Project的用法示例。


在下文中一共展示了Project.GetItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Project

        public Project(Solution solution, string title, string fileName)
        {
            AssembliesResolved = false;
            ReferencedAssemblies = new List<string>();
            CompilerSettings = new CompilerSettings();
            ReferencedProjects = new List<string>();
            Files = new List<File>();
            Solution = solution;
            Title = title;
            FileName = Path.GetFullPath(fileName);

            ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
            MsBuildProject = new Microsoft.Build.Evaluation.Project(fileName);

            AssemblyName = MsBuildProject.GetPropertyValue("AssemblyName");
            CompilerSettings.AllowUnsafeBlocks = MsBuildProject.GetPropertyAsBoolean("AllowUnsafeBlocks");
            CompilerSettings.CheckForOverflow = MsBuildProject.GetPropertyAsBoolean("CheckForOverflowUnderflow");
            var defineConstants = MsBuildProject.GetPropertyValue("DefineConstants");

            foreach (string symbol in defineConstants.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                CompilerSettings.ConditionalSymbols.Add(symbol.Trim());
            }

            foreach (var sourceCodeFile in MsBuildProject.GetItems("Compile"))
            {
                Files.Add(new File(this, Path.Combine(MsBuildProject.DirectoryPath, sourceCodeFile.EvaluatedInclude)));
            }

            foreach (var projectReference in MsBuildProject.GetItems("ProjectReference"))
            {
                string referencedFileName = Path.GetFullPath(Path.Combine(MsBuildProject.DirectoryPath, projectReference.EvaluatedInclude));
                ReferencedProjects.Add(referencedFileName);
            }
        }
开发者ID:rpepato,项目名称:StructEx,代码行数:35,代码来源:Project.cs

示例2: CreateCompilation

        private Compilation CreateCompilation(Project project)
        {
            var outputPath = project.GetProperty("OutputPath").EvaluatedValue;

            if (!Path.IsPathRooted(outputPath))
            {
                outputPath = Path.Combine(Environment.CurrentDirectory, outputPath);
            }

            var searchPaths = ReadOnlyArray.OneOrZero(outputPath);
            var resolver = new DiskFileResolver(searchPaths, searchPaths, Environment.CurrentDirectory, arch => true, System.Globalization.CultureInfo.CurrentCulture);

            var metadataFileProvider = new MetadataFileProvider();

            // just grab a list of references (if they're null, ignore)
            var list = project.GetItems("Reference").Select(item =>
            {
                var include = item.EvaluatedInclude;
                var path = resolver.ResolveAssemblyName(include);
                if (path == null) return null;
                return metadataFileProvider.GetReference(path);
            }).Where(x => x != null);

            return Compilation.Create(project.GetPropertyValue("AssemblyName"),
                syntaxTrees: project.GetItems("Compile").Select(c => SyntaxTree.ParseFile(c.EvaluatedInclude)),
                references: list);
        }
开发者ID:pmacn,项目名称:DocPlagiarizer,代码行数:27,代码来源:DocPlagiarizerTask.cs

示例3: SortProject

 private IEnumerable<Project> SortProject(Project project)
 {
     if (!visited.Contains(project)) {
         visited.Add(project);
         foreach (var reference in project.GetItems("Reference")) {
             //TODO: Get rid of hard-coded exclusions
             if (reference.EvaluatedInclude != "DevExpress.XtraRichEdit.v12.2.Extensions, Version=12.2.0.0, Culture=neutral, PublicKeyToken=79868b8147b5eae4, processorArchitecture=MSIL") {
                 AssemblyName assemblyName = new AssemblyName(reference.EvaluatedInclude);
                 string shortName = assemblyName.Name;
                 Project referencedProject;
                 if (projects.TryGetValue(shortName, out referencedProject)) {
                     foreach (var sorted in SortProject(referencedProject))
                         yield return sorted;
                 }
                 else if (excludedProjects.Contains(shortName)) {
                     excludedProjects.Add(shortName);
                     yield break;
                 }
                 else if (shortName.StartsWith("DevExpress", StringComparison.OrdinalIgnoreCase))
                     unknownReferences.Add(shortName);
             }
         }
         yield return project;
     }
 }
开发者ID:uQr,项目名称:DXBuildGenerator,代码行数:25,代码来源:SortedProjects.cs

示例4: SimpleImportAndSemanticValues

		public void SimpleImportAndSemanticValues ()
		{
			string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <Import Project='test_imported.proj' />
</Project>";
			string imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <A>x</A>
    <B>y</B>
  </PropertyGroup>
  <ItemGroup>
    <X Include=""included.txt"" />
  </ItemGroup>
</Project>";
			using (var ts = File.CreateText (temp_file_name))
				ts.Write (imported);
			try {
				var reader = XmlReader.Create (new StringReader (xml));
				var root = ProjectRootElement.Create (reader);
				Assert.AreEqual (temp_file_name, root.Imports.First ().Project, "#1");
				var proj = new Project (root);
				var prop = proj.GetProperty ("A");
				Assert.IsNotNull (prop, "#2");
				Assert.IsTrue (prop.IsImported, "#3");
				var item = proj.GetItems ("X").FirstOrDefault ();
				Assert.IsNotNull (item, "#4");
				Assert.AreEqual ("included.txt", item.EvaluatedInclude, "#5");
			} finally {
				File.Delete (temp_file_name);
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:31,代码来源:ResolvedImportTest.cs

示例5: PackageContainsContentItemsAsync

 public static async Task PackageContainsContentItemsAsync(Project nuProj)
 {
     var package = await nuProj.GetPackageAsync();
     
     foreach (var contentItem in nuProj.GetItems("Content"))
     {
         var expectedPath = GetExpectedPackagePathForContent(contentItem);
         Assert.NotNull(package.GetFile(expectedPath));
     }
 }
开发者ID:NN---,项目名称:nuproj,代码行数:10,代码来源:AssertNu.cs

示例6: SetUnevaluatedValue

        public void SetUnevaluatedValue()
        {
            string content = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace' >
                        <ItemGroup>
                            <i Include='i1'>
                                <m1>v1</m1>
                                <m2>v%253</m2>
                            </i>
                        </ItemGroup>
                    </Project>
                ");

            ProjectRootElement projectXml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            Project project = new Project(projectXml);

            Assert.AreEqual(false, project.IsDirty);

            Helpers.GetFirst(project.GetItems("i")).SetMetadataValue("m1", "v2");
            Helpers.GetFirst(project.GetItems("i")).SetMetadataValue("m2", "v%214");

            Assert.AreEqual(true, project.IsDirty);

            StringWriter writer = new StringWriter();
            projectXml.Save(writer);

            string expected = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace' >
                        <ItemGroup>
                            <i Include='i1'>
                                <m1>v2</m1>
                                <m2>v%214</m2>
                            </i>
                        </ItemGroup>
                    </Project>
                ");

            Helpers.CompareProjectXml(expected, writer.ToString());
            Assert.AreEqual("v!4", Helpers.GetFirst(project.GetItems("i")).GetMetadataValue("m2"));
        }
开发者ID:ravpacheco,项目名称:msbuild,代码行数:40,代码来源:ProjectMetadata_Tests.cs

示例7: SetMetadata

        public void SetMetadata()
        {
            ProjectRootElement xml = ProjectRootElement.Create();
            xml.AddProperty("p", "v");
            xml.AddItemDefinitionGroup().AddItemDefinition("i").AddMetadata("m", "m0");
            xml.AddItem("i", "i1");

            Project project = new Project(xml);

            ProjectMetadata metadatum = project.ItemDefinitions["i"].GetMetadata("m");

            metadatum.UnevaluatedValue = "$(p)";

            Assert.Equal("v", Helpers.GetFirst(project.GetItems("i")).GetMetadataValue("m"));
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:15,代码来源:ProjectItemDefinition_Tests.cs

示例8: GetProjectReferences

    static IEnumerable<Project> GetProjectReferences(Project project)
    {
        foreach (var reference in project.GetItems("ProjectReference"))
        {
            var referenced = new Project(
                    Path.Combine(Path.GetDirectoryName(project.FullPath), reference.EvaluatedInclude),
                    project.GlobalProperties,
                    project.ToolsVersion,
                    new ProjectCollection(project.GlobalProperties));

            yield return referenced;
            foreach (var transitive in GetProjectReferences(referenced))
            {
                yield return transitive;
            }
        }
    }
开发者ID:xamarin,项目名称:NuGetizer3000,代码行数:17,代码来源:Builder.cs

示例9: AddItem_EscapedItemInclude

        public void AddItem_EscapedItemInclude()
        {
            Project project = new Project();

            project.AddItem("i", "i%281%29");

            string expected = ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <ItemGroup>
    <i Include=""i%281%29"" />
  </ItemGroup>
</Project>");

            Helpers.VerifyAssertProjectContent(expected, project.Xml);

            List<ProjectItem> items = Helpers.MakeList(project.Items);
            Assert.Equal(1, items.Count);
            Assert.Equal("i", items[0].ItemType);
            Assert.Equal("i(1)", items[0].EvaluatedInclude);
            Assert.Equal("i(1)", Helpers.GetFirst(project.GetItems("i")).EvaluatedInclude);
            Assert.Equal("i(1)", Helpers.MakeList(project.CreateProjectInstance().GetItems("i"))[0].EvaluatedInclude);
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:22,代码来源:DefinitionEditing_Tests.cs

示例10: AddAllProjectReferences

        private static IProjectContent AddAllProjectReferences(Project msbuildProject, IProjectContent pc)
        {
            foreach (var item in msbuildProject.GetItems("ProjectReference"))
            {
                var referencedFileName = Path.Combine(msbuildProject.DirectoryPath, item.EvaluatedInclude);
                referencedFileName = Path.GetFullPath(referencedFileName);

                pc = pc.AddAssemblyReferences(new[] {new ProjectReference(referencedFileName)});
            }
            return pc;
        }
开发者ID:JoeHosman,项目名称:sharpDox,代码行数:11,代码来源:CSharpProject.cs

示例11: GetImportedItem

        /// <summary>
        /// Gets the test item from the import.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <returns>The item.</returns>
        private ProjectItem GetImportedItem(Project project)
        {
            IEnumerable<ProjectItem> items = project.GetItems(ItemType).Where(pi => pi.IsImported);
            Assert.IsTrue(items.Count() == 1, "Wrong number of items in the import.");

            ProjectItem item = items.First();
            Assert.AreEqual(importFilename, item.Xml.ContainingProject.FullPath, "Item was not found in the imported project.");

            return item;
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:15,代码来源:ProtectImports_Tests.cs

示例12: CanGetCorrectListOfItemsWithSemicolonsInThem2

        public void CanGetCorrectListOfItemsWithSemicolonsInThem2()
        {
            string projectString = @"
                <Project DefaultTargets=""Build"" ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <PropertyGroup>
                        <MyUserMacro>foo;bar</MyUserMacro>
                    </PropertyGroup>
                    <ItemGroup>
                        <CrazyList Include=""a"" />
                        <CrazyList Include=""b%3bc"" />
                        <CrazyList Include=""$(MyUserMacro)"" />
                    </ItemGroup>
                </Project>";

            System.Xml.XmlReader reader = new System.Xml.XmlTextReader(new StringReader(projectString));
            Project project = new Project(reader);
            IEnumerable<ProjectItem> items = project.GetItems("CrazyList");

            Assert.Equal(4, items.Count());
            Assert.Equal(items.ElementAt(0).EvaluatedInclude, "a");
            Assert.Equal(items.ElementAt(1).EvaluatedInclude, "b;c");
            Assert.Equal(items.ElementAt(2).EvaluatedInclude, "foo");
            Assert.Equal(items.ElementAt(3).EvaluatedInclude, "bar");
        }
开发者ID:cdmihai,项目名称:msbuild,代码行数:24,代码来源:EscapingInProjects_Tests.cs

示例13: ModifyItemOfTypeInProject

        /// <summary>
        /// Given a project and an item type, gets the items of that type, and renames an item
        /// with the old evaluated include to have the new evaluated include instead.  
        /// </summary>
        /// <param name="project"></param>
        /// <param name="itemType"></param>
        /// <param name="oldEvaluatedInclude"></param>
        /// <param name="newEvaluatedInclude"></param>
        internal static IEnumerable<ProjectItem> ModifyItemOfTypeInProject(Project project, string itemType, string oldEvaluatedInclude, string newEvaluatedInclude)
        {
            IEnumerable<ProjectItem> itemsToMatch = project.GetItems(itemType);
            List<ProjectItem> matchingItems = new List<ProjectItem>();

            foreach (ProjectItem item in itemsToMatch)
            {
                if (String.Equals(item.EvaluatedInclude, oldEvaluatedInclude, StringComparison.OrdinalIgnoreCase))
                {
                    matchingItems.Add(item);
                }
            }

            for (int i = 0; i < matchingItems.Count; i++)
            {
                matchingItems[i].Rename(newEvaluatedInclude);
            }

            return matchingItems;
        }
开发者ID:cdmihai,项目名称:msbuild,代码行数:28,代码来源:EscapingInProjects_Tests.cs

示例14: TransformsUseCorrectDirectory_DirectoryNameItemFunction

        public void TransformsUseCorrectDirectory_DirectoryNameItemFunction()
        {
            string file = null;

            string projectFileContent = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace'>
                        <ItemGroup>
                            <IntermediateAssembly Include='obj\i386\foo.dll'/>
                            <BuiltProjectOutputGroupKeyOutput Include=""@(IntermediateAssembly->DirectoryName())""/>
                        </ItemGroup>
                    </Project>");

            ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(projectFileContent)));

            try
            {
                file = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile();
                xml.FullPath = file;

                Project project = new Project(xml);
                ProjectInstance projectInstance = new ProjectInstance(xml);

                // Should be the full path to the directory
                Assert.Equal(Path.Combine(Path.GetTempPath() /* remove c:\ */, @"obj\i386"), project.GetItems("BuiltProjectOutputGroupKeyOutput").First().EvaluatedInclude);
                Assert.Equal(Path.Combine(Path.GetTempPath() /* remove c:\ */, @"obj\i386"), projectInstance.GetItems("BuiltProjectOutputGroupKeyOutput").First().EvaluatedInclude);
            }
            finally
            {
                File.Delete(file);
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:31,代码来源:Project_Tests.cs

示例15: TransformsUseCorrectDirectory_Basic

        public void TransformsUseCorrectDirectory_Basic()
        {
            string file = null;

            string projectFileContent = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace'>
                        <ItemGroup>
                            <IntermediateAssembly Include='obj\i386\foo.dll'/>
                            <BuiltProjectOutputGroupKeyOutput Include=""@(IntermediateAssembly->'%(FullPath)')""/>
                        </ItemGroup>
                    </Project>");

            ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(projectFileContent)));

            Project project = new Project(xml);

            try
            {
                file = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile();
                project.Save(file);
                project.ReevaluateIfNecessary();

                Assert.Equal(Path.Combine(Path.GetTempPath(), @"obj\i386\foo.dll"), project.GetItems("BuiltProjectOutputGroupKeyOutput").First().EvaluatedInclude);
            }
            finally
            {
                File.Delete(file);
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:29,代码来源:Project_Tests.cs


注:本文中的Microsoft.Build.Evaluation.Project.GetItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。