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


C# Project.GetEvaluatedItemsByName方法代码示例

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


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

示例1: LoadSpecFlowProjectFromMsBuild

        public static SpecFlowProject LoadSpecFlowProjectFromMsBuild(string projectFile)
        {
            projectFile = Path.GetFullPath(projectFile);
            Project project = new Project();
            project.Load(projectFile, ProjectLoadSettings.IgnoreMissingImports);

            string projectFolder = Path.GetDirectoryName(projectFile);

            SpecFlowProject specFlowProject = new SpecFlowProject();
            specFlowProject.ProjectFolder = projectFolder;
            specFlowProject.ProjectName = Path.GetFileNameWithoutExtension(projectFile);
            specFlowProject.AssemblyName = project.GetEvaluatedProperty("AssemblyName");
            specFlowProject.DefaultNamespace = project.GetEvaluatedProperty("RootNamespace");

            var items = project.GetEvaluatedItemsByName("None").Cast<BuildItem>()
                .Concat(project.GetEvaluatedItemsByName("Content").Cast<BuildItem>());
            foreach (BuildItem item in items)
            {
                var extension = Path.GetExtension(item.FinalItemSpec);
                if (extension.Equals(".feature", StringComparison.InvariantCultureIgnoreCase))
                {
                    var featureFile = new SpecFlowFeatureFile(item.FinalItemSpec);
                    var ns = item.GetEvaluatedMetadata("CustomToolNamespace");
                    if (!String.IsNullOrEmpty(ns))
                        featureFile.CustomNamespace = ns;
                    specFlowProject.FeatureFiles.Add(featureFile);
                }

                if (Path.GetFileName(item.FinalItemSpec).Equals("app.config", StringComparison.InvariantCultureIgnoreCase))
                {
                    GeneratorConfigurationReader.UpdateConfigFromFile(specFlowProject.GeneratorConfiguration, Path.Combine(projectFolder, item.FinalItemSpec));
                }
            }
            return specFlowProject;
        }
开发者ID:xerxesb,项目名称:SpecFlow,代码行数:35,代码来源:MsBuildProjectReader.cs

示例2: CompileProject

        public Assembly CompileProject(string projectFileName)
        {
            Assembly existing;
            if (Compilations.TryGetValue(Path.GetFullPath(projectFileName), out existing))
            {
                return existing;
            }

            var project = new Microsoft.Build.BuildEngine.Project();
            project.Load(projectFileName);

            var projectName = Environment.NameTable.GetNameFor(project.EvaluatedProperties["AssemblyName"].Value);
            var projectPath = project.FullFileName;
            var compilerOptions = new SpecSharpOptions();
            var assemblyReferences = new List<IAssemblyReference>();
            var moduleReferences = new List<IModuleReference>();
            var programSources = new List<SpecSharpSourceDocument>();
            var assembly = new SpecSharpAssembly(projectName, projectPath, Environment, compilerOptions, assemblyReferences, moduleReferences, programSources);
            var helper = new SpecSharpCompilationHelper(assembly.Compilation);

            Compilations[Path.GetFullPath(projectFileName)] = assembly;

            assemblyReferences.Add(Environment.LoadAssembly(Environment.CoreAssemblySymbolicIdentity));
            project.Build("ResolveAssemblyReferences");
            foreach (BuildItem item in project.GetEvaluatedItemsByName("ReferencePath"))
            {
                var assemblyName = new System.Reflection.AssemblyName(item.GetEvaluatedMetadata("FusionName"));
                var name = Environment.NameTable.GetNameFor(assemblyName.Name);
                var culture = assemblyName.CultureInfo != null ? assemblyName.CultureInfo.Name : "";
                var version = assemblyName.Version == null ? new Version(0, 0) : assemblyName.Version;
                var token = assemblyName.GetPublicKeyToken();
                if (token == null) token = new byte[0];
                var location = item.FinalItemSpec;
                var identity = new AssemblyIdentity(name, culture, version, token, location);
                var reference = Environment.LoadAssembly(identity);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("ProjectReference"))
            {
                var name = Environment.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(item.FinalItemSpec));
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var reference = CompileProject(location);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("Compile"))
            {
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var name = Environment.NameTable.GetNameFor(location);
                var programSource = new SpecSharpSourceDocument(helper, name, location, File.ReadAllText(location));
                programSources.Add(programSource);
            }

            return assembly;
        }
开发者ID:dbremner,项目名称:specsharp,代码行数:56,代码来源:MSBuildCompiler.cs

示例3: ResolveBinary_FancyStuff

		public void ResolveBinary_FancyStuff ()
		{
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\FancyStuff.dll"));
			
			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big[0].Include.EndsWith ("FancyStuff.dll"), "A3");
			
			big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
			Assert.AreEqual (1, big.Count, "A4");
			Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5");
		}
开发者ID:sri-prasanna,项目名称:mono,代码行数:15,代码来源:ResolveAssemblyReferenceTest.cs

示例4: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		public override bool Execute() {
			foreach (ITaskItem taskItem in this.Projects) {
				switch (GetClassification(taskItem)) {
					case ProjectClassification.VS2010Project:
						this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
						Project project = new Project();
						project.Load(taskItem.ItemSpec);
						project.DefaultToolsVersion = "3.5";

						if (this.DowngradeMvc2ToMvc1) {
							string projectTypeGuids = project.GetEvaluatedProperty("ProjectTypeGuids");
							if (!string.IsNullOrEmpty(projectTypeGuids)) {
								projectTypeGuids = projectTypeGuids.Replace("{F85E285D-A4E0-4152-9332-AB1D724D3325}", "{603c0e0b-db56-11dc-be95-000d561079b0}");
								project.SetProperty("ProjectTypeGuids", projectTypeGuids);
							}
						}

						// Web projects usually have an import that includes these substrings
						foreach (Import import in project.Imports) {
							import.ProjectPath = import.ProjectPath
								.Replace("$(MSBuildExtensionsPath32)", "$(MSBuildExtensionsPath)")
								.Replace("VisualStudio\\v10.0", "VisualStudio\\v9.0");
						}

						// VS2010 won't let you have a System.Core reference, but VS2008 requires it.
						BuildItemGroup references = project.GetEvaluatedItemsByName("Reference");
						if (!references.Cast<BuildItem>().Any(item => item.FinalItemSpec.StartsWith("System.Core", StringComparison.OrdinalIgnoreCase))) {
							project.AddNewItem("Reference", "System.Core");
						}

						project.Save(taskItem.ItemSpec);
						break;
					case ProjectClassification.VS2010Solution:
						this.Log.LogMessage(MessageImportance.Low, "Downgrading solution \"{0}\".", taskItem.ItemSpec);
						string[] contents = File.ReadAllLines(taskItem.ItemSpec);
						if (contents[1] != "Microsoft Visual Studio Solution File, Format Version 11.00" ||
							contents[2] != "# Visual Studio 2010") {
							this.Log.LogError("Unrecognized solution file header in \"{0}\".", taskItem.ItemSpec);
							break;
						}

						contents[1] = "Microsoft Visual Studio Solution File, Format Version 10.00";
						contents[2] = "# Visual Studio 2008";

						for (int i = 3; i < contents.Length; i++) {
							contents[i] = contents[i].Replace("TargetFrameworkMoniker = \".NETFramework,Version%3Dv", "TargetFramework = \"");
						}

						File.WriteAllLines(taskItem.ItemSpec, contents);
						break;
					default:
						this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
						break;
				}
			}

			return !this.Log.HasLoggedErrors;
		}
开发者ID:jongalloway,项目名称:dotnetopenid,代码行数:61,代码来源:DowngradeProjects.cs

示例5: TestHintPath1

		public void TestHintPath1 ()
		{
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (ResolveAssembly (null, @"Test\resources\test.dll"));
			
			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:ResolveAssemblyReferenceTest.cs

示例6: Execute

		public override bool Execute() {
			foreach (var project in Projects) {
				Project doc = new Project();
				doc.Load(project.ItemSpec);
				
				var reference = doc.GetEvaluatedItemsByName("Reference").OfType<BuildItem>().
					Where(item => string.Equals(item.GetMetadata("HintPath"), OldReference, StringComparison.OrdinalIgnoreCase)).Single();
				reference.SetMetadata("HintPath", NewReference);

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:14,代码来源:ChangeAssemblyReference.cs

示例7: TestGac1

		public void TestGac1 ()
		{
			var gacDir = GetGacDir ();

			if (gacDir == null || !System.IO.Directory.Exists (gacDir))
				Assert.Ignore ("GAC not found.");

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (ResolveAssembly ("System", null));
			
			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:ResolveAssemblyReferenceTest.cs

示例8: GetItems

		private string GetItems (Project proj, string name)
		{
			BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
			string str = String.Empty;
			if (big == null)
				return str;

			foreach (BuildItem bi in big) {
				if (str == String.Empty)
					str = bi.FinalItemSpec;
				else 
					str += ";" + bi.FinalItemSpec;
			}
			
			return str;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:16,代码来源:Items.cs

示例9: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		public override bool Execute() {
			if (this.References.Length == 0 || this.Projects.Length == 0) {
				this.Log.LogMessage(MessageImportance.Low, "Skipping reference hintpath fixup because no projects or no references were supplied.");
				return !this.Log.HasLoggedErrors;
			}

			// Figure out what the assembly names are of the references that are available.
			AssemblyName[] availableReferences = new AssemblyName[this.References.Length];
			for (int i = 0; i < this.References.Length; i++) {
				if (File.Exists(this.References[i].ItemSpec)) {
					availableReferences[i] = AssemblyName.GetAssemblyName(this.References[i].ItemSpec);
				} else {
					availableReferences[i] = new AssemblyName(Path.GetFileNameWithoutExtension(this.References[i].ItemSpec)) {
						CodeBase = this.References[i].GetMetadata("FullPath"),
					};
				}
			}

			foreach (var projectTaskItem in this.Projects) {
				var project = new Project();
				Uri projectUri = new Uri(projectTaskItem.GetMetadata("FullPath"));
				project.Load(projectTaskItem.ItemSpec);

				foreach (BuildItem referenceItem in project.GetEvaluatedItemsByName("Reference")) {
					var referenceAssemblyName = new AssemblyName(referenceItem.Include);
					var matchingReference = availableReferences.FirstOrDefault(r => string.Equals(r.Name, referenceAssemblyName.Name, StringComparison.OrdinalIgnoreCase));
					if (matchingReference != null) {
						var originalSuppliedReferenceItem = this.References[Array.IndexOf(availableReferences, matchingReference)];
						string hintPath = originalSuppliedReferenceItem.GetMetadata("HintPath");
						if (string.IsNullOrEmpty(hintPath)) {
							hintPath = projectUri.MakeRelativeUri(new Uri(matchingReference.CodeBase)).OriginalString.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
						}
						this.Log.LogMessage("Fixing up HintPath to \"{0}\" in project \"{1}\".", referenceAssemblyName.Name, projectTaskItem.ItemSpec);
						referenceItem.SetMetadata("HintPath", hintPath);
					}
				}

				project.Save(projectTaskItem.ItemSpec);
			}

			return !this.Log.HasLoggedErrors;
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:45,代码来源:FixupReferenceHintPaths.cs

示例10: TestGac1

		public void TestGac1 ()
		{
			string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<ItemGroup>
						<Reference Include='System' />
					</ItemGroup>
					<PropertyGroup>
						<SearchPaths>
							{CandidateAssemblyFiles};
							$(ReferencePath);
							{HintPathFromItem};
							{TargetFrameworkDirectory};
							{AssemblyFolders};
							{GAC};
							{RawFileName};
							$(OutputPath)
						</SearchPaths>
					</PropertyGroup>
					<Target Name='A'>
						<ResolveAssemblyReference
							Assemblies='@(Reference)'
							SearchPaths='$(SearchPaths)'
						>
							<Output TaskParameter='ResolvedFiles' ItemName='ResolvedFiles'/>
						</ResolveAssemblyReference>
					</Target>
				</Project>
			";
			
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);

			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:39,代码来源:ResolveAssemblyReferenceTest.cs

示例11: CheckItems

		private void CheckItems (Project proj, string name, string prefix, params string [] values)
		{
			BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
			if (big == null) {
				Assert.Fail ("{0}: Item corresponding '{1}' not found.", prefix, name);
				return;
			}

			if (values.Length != big.Count) {
				Console.Write ("Expected> ");
				foreach (string s in values)
					Console.Write ("{0}|", s);
				Console.WriteLine ();
				Console.Write ("Actual> ");
				foreach (BuildItem item in big)
					Console.Write ("{0}|", item.FinalItemSpec);
				Console.WriteLine ();
				Assert.AreEqual (values.Length, big.Count, String.Format ("{0}: Number of items", prefix));
			}
			for (int i = 0; i < values.Length; i ++)
				Assert.AreEqual (values [i], big [i].FinalItemSpec,
					String.Format ("{0}: Item named {1}, numbered {2}", prefix, name, i));
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:23,代码来源:Items.cs

示例12: Execute

		public override bool Execute() {
			if (this.ProjectReferences.Length != this.References.Length) {
				this.Log.LogError("ProjectReferences and References arrays do not have matching lengths.");
				this.Log.LogError("ProjectReferences contents ({0} elements): {1}", this.ProjectReferences.Length, String.Join<ITaskItem>(";", this.ProjectReferences));
				this.Log.LogError("References contents ({0} elements): {1}", this.References.Length, String.Join<ITaskItem>(";", this.References));
				return false;
			}

			foreach (var project in Projects) {
				Project doc = new Project();
				doc.Load(project.ItemSpec, ProjectLoadSettings.IgnoreMissingImports);

				var projectReferences = doc.EvaluatedItems.OfType<BuildItem>().Where(item => item.Name == "ProjectReference");
				var matchingReferences = from reference in projectReferences
										 join refToRemove in this.ProjectReferences on reference.Include equals refToRemove.ItemSpec
										 let addIndex = Array.IndexOf(this.ProjectReferences, refToRemove)
										 select new { Remove = reference, Add = this.References[addIndex] };
				foreach (var matchingReference in matchingReferences) {
					this.Log.LogMessage("Removing project reference to \"{0}\" from \"{1}\".", matchingReference.Remove.Include, project.ItemSpec);
					doc.RemoveItem(matchingReference.Remove);
					if (matchingReference.Add.ItemSpec != "REMOVE") {
						this.Log.LogMessage("Adding assembly reference to \"{0}\" to \"{1}\".", matchingReference.Add.ItemSpec, project.ItemSpec);

						string newItemSpec = Path.GetFileNameWithoutExtension(matchingReference.Add.ItemSpec);
						if (!doc.GetEvaluatedItemsByName("Reference").OfType<BuildItem>().Any(bi => String.Equals(bi.Include, newItemSpec, StringComparison.OrdinalIgnoreCase))) {
							var newReference = doc.AddNewItem("Reference", newItemSpec, true);
							newReference.SetMetadata("HintPath", matchingReference.Add.ItemSpec);
						}
					}
				}

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:36,代码来源:ChangeProjectReferenceToAssemblyReference.cs

示例13: GetEvaluatedItemsByNameDoesNotExistItem

 public void GetEvaluatedItemsByNameDoesNotExistItem()
 {
     Project p = new Project();
     string name = "notFound";
     BuildItemGroup emptyGroup = p.GetEvaluatedItemsByName(name);
     Assertion.AssertEquals(0, emptyGroup.Count);  
 }
开发者ID:nikson,项目名称:msbuild,代码行数:7,代码来源:Project_Tests.cs

示例14: foreach

        /// <summary>
        /// This helper method checks the project to determine whether a particular item of a particular
        /// name exists in the project, such that the build process (the tasks) would see it.
        /// </summary>
        /// <param name="project"></param>
        /// <param name="itemType"></param>
        /// <param name="itemSpec"></param>
        /// <returns></returns>
        /// <owner>RGoel</owner>
        private bool ItemExistsInBuildProcessHelper
            (
            Project project,
            string itemType,
            string itemSpec
            )
        {
            BuildItemGroup evaluatedItemsOfParticularType = project.GetEvaluatedItemsByName(itemType);

            Assertion.AssertNotNull(evaluatedItemsOfParticularType);

            // Search all the evaluated items for the one with the item spec we want
            // to remove.
            foreach (BuildItem evaluatedItem in evaluatedItemsOfParticularType)
            {
                if (evaluatedItem.FinalItemSpecEscaped == itemSpec)
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:32,代码来源:Project_Tests.cs

示例15: GetEvaluatedItemsByNameTwoItems

 public void GetEvaluatedItemsByNameTwoItems()
 {
     Project p = new Project();
     string name = "new";
     p.SetProperty("condition", "false");            
     BuildItem buildItem = p.AddNewItem(name, "i1");
     buildItem.Condition = "$(condition)";
     p.AddNewItem(name, "i2");
     BuildItemGroup foundGroup = p.GetEvaluatedItemsByName(name);
     Assertion.AssertEquals(1, foundGroup.Count);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:11,代码来源:Project_Tests.cs


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