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


C# Project.AddNewItem方法代码示例

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


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

示例1: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		public override bool Execute() {
			foreach (var projectTaskItem in this.Projects) {
				var project = new Project();
				project.Load(projectTaskItem.ItemSpec);

				foreach (var projectItem in this.Items) {
					string itemType = projectItem.GetMetadata("ItemType");
					if (string.IsNullOrEmpty(itemType)) {
						itemType = "None";
					}
					BuildItem newItem = project.AddNewItem(itemType, projectItem.ItemSpec, false);
					var customMetadata = projectItem.CloneCustomMetadata();
					foreach (DictionaryEntry entry in customMetadata) {
						string value = (string)entry.Value;
						if (value.Length > 0) {
							newItem.SetMetadata((string)entry.Key, value);
						}
					}
				}

				project.Save(projectTaskItem.ItemSpec);
			}

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

示例2: Execute

		public override bool Execute() {
			if (this.ProjectReferences.Length != this.References.Length) {
				this.Log.LogError("ProjectReferences and References arrays do not have matching lengths.");
			}

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

				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);
						var newReference = doc.AddNewItem("Reference", Path.GetFileNameWithoutExtension(matchingReference.Add.ItemSpec), true);
						newReference.SetMetadata("HintPath", matchingReference.Add.ItemSpec);
					}
				}

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:jongalloway,项目名称:dotnetopenid,代码行数:29,代码来源:ChangeProjectReferenceToAssemblyReference.cs

示例3: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		/// <returns></returns>
		public override bool Execute() {
			foreach (ITaskItem projectTaskItem in this.Projects) {
				this.Log.LogMessage("Fixing up the {0} sample for shipping as source code.", Path.GetFileNameWithoutExtension(projectTaskItem.ItemSpec));

				var project = new Project();
				Uri projectUri = new Uri(projectTaskItem.GetMetadata("FullPath"));
				project.Load(projectTaskItem.ItemSpec, ProjectLoadSettings.IgnoreMissingImports);

				if (this.RemoveImportsStartingWith != null && this.RemoveImportsStartingWith.Length > 0) {
					project.Imports.Cast<Import>()
						.Where(import => this.RemoveImportsStartingWith.Any(start => import.ProjectPath.StartsWith(start, StringComparison.OrdinalIgnoreCase)))
						.ToList()
						.ForEach(import => project.Imports.RemoveImport(import));
				}

				if (this.AddReferences != null) {
					foreach (var reference in this.AddReferences) {
						BuildItem item = project.AddNewItem("Reference", reference.ItemSpec);
						foreach (DictionaryEntry metadata in reference.CloneCustomMetadata()) {
							item.SetMetadata((string)metadata.Key, (string)metadata.Value);
						}
					}
				}

				project.Save(projectTaskItem.ItemSpec);
			}

			return !this.Log.HasLoggedErrors;
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:33,代码来源:FixupShippingToolSamples.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: Execute

		public override bool Execute() {
			foreach (var project in Projects) {
				Project doc = new Project();
				doc.Load(project.ItemSpec);
				
				var projectReference = doc.EvaluatedItems.OfType<BuildItem>().Where(
					item => item.Name == "ProjectReference" && item.Include == ProjectReference).Single();
				doc.RemoveItem(projectReference);

				var newReference = doc.AddNewItem("Reference", Path.GetFileNameWithoutExtension(Reference));
				newReference.SetMetadata("HintPath", Reference);

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:Belxjander,项目名称:Asuna,代码行数:17,代码来源:ChangeProjectReferenceToAssemblyReference.cs

示例6: 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

示例7: AddNewItemInclude_Empty

 public void AddNewItemInclude_Empty()
 {
     Project p = new Project();
     p.AddNewItem("include", String.Empty);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:5,代码来源:Project_Tests.cs

示例8: AddNewItem

 public override void AddNewItem(Project project, string name, string include)
 {
     project.AddNewItem(name, include);
 }
开发者ID:redrezo,项目名称:gradle-msbuild-plugin,代码行数:4,代码来源:MsbuildPlatform.cs

示例9: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		public override bool Execute() {
			var newProjectToOldProjectMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
			var createdProjectFiles = new List<TaskItem>();

			foreach (ITaskItem taskItem in this.Projects) {
				switch (GetClassification(taskItem)) {
					case ProjectClassification.VS2010Project:
					case ProjectClassification.VS2010Solution:
						string projectNameForVS2008 = InPlaceDowngrade
														? taskItem.ItemSpec
														: Path.Combine(
															Path.GetDirectoryName(taskItem.ItemSpec),
															Path.GetFileNameWithoutExtension(taskItem.ItemSpec) + "-vs2008" +
															Path.GetExtension(taskItem.ItemSpec));
						newProjectToOldProjectMapping[taskItem.ItemSpec] = projectNameForVS2008;
						break;
				}
			}

			foreach (ITaskItem taskItem in this.Projects) {
				switch (GetClassification(taskItem)) {
					case ProjectClassification.VS2010Project:
						this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
						var project = new Project();
						project.Load(taskItem.ItemSpec, ProjectLoadSettings.IgnoreMissingImports);
						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);
							}
						}

						// MSBuild v3.5 doesn't support the GetDirectoryNameOfFileAbove function
						var enlistmentInfoImports = project.Imports.Cast<Import>().Where(i => i.ProjectPath.IndexOf("[MSBuild]::GetDirectoryNameOfFileAbove", StringComparison.OrdinalIgnoreCase) >= 0);
						enlistmentInfoImports.ToList().ForEach(i => project.Imports.RemoveImport(i));

						// 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");
						}

						// Rewrite ProjectReferences to other renamed projects.
						BuildItemGroup projectReferences = project.GetEvaluatedItemsByName("ProjectReference");
						foreach (var mapping in newProjectToOldProjectMapping) {
							string oldName = Path.GetFileName(mapping.Key);
							string newName = Path.GetFileName(mapping.Value);
							foreach (BuildItem projectReference in projectReferences) {
								projectReference.Include = Regex.Replace(projectReference.Include, oldName, newName, RegexOptions.IgnoreCase);
							}
						}

						project.Save(newProjectToOldProjectMapping[taskItem.ItemSpec]);
						createdProjectFiles.Add(new TaskItem(taskItem) { ItemSpec = newProjectToOldProjectMapping[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 = \"");
						}

						foreach (var mapping in newProjectToOldProjectMapping) {
							string oldName = Path.GetFileName(mapping.Key);
							string newName = Path.GetFileName(mapping.Value);
							for (int i = 0; i < contents.Length; i++) {
								contents[i] = Regex.Replace(contents[i], oldName, newName, RegexOptions.IgnoreCase);
							}
						}

						File.WriteAllLines(newProjectToOldProjectMapping[taskItem.ItemSpec], contents);
						createdProjectFiles.Add(new TaskItem(taskItem) { ItemSpec = newProjectToOldProjectMapping[taskItem.ItemSpec] });
						break;
					default:
						this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
						break;
				}
			}
//.........这里部分代码省略.........
开发者ID:Balamir,项目名称:DotNetOpenAuth,代码行数:101,代码来源:DowngradeProjects.cs

示例10: CreateBuildProject

        /// <summary>
        /// Creates a temporary MSBuild content project in memory.
        /// </summary>
        void CreateBuildProject()
        {
            string projectPath = Path.Combine(buildDirectory, "content.contentproj");
            string outputPath = Path.Combine(buildDirectory, "bin");

            // Create the build engine.
            msBuildEngine = new Engine(RuntimeEnvironment.GetRuntimeDirectory());

            // Hook up our custom error logger.
            errorLogger = new ErrorLogger();

            msBuildEngine.RegisterLogger(errorLogger);

            // Create the build project.
            msBuildProject = new Project(msBuildEngine);

            msBuildProject.FullFileName = projectPath;

            msBuildProject.SetProperty("XnaPlatform", "Windows");
            msBuildProject.SetProperty("XnaFrameworkVersion", "v2.0");
            msBuildProject.SetProperty("Configuration", "Release");
            msBuildProject.SetProperty("OutputPath", outputPath);

            // Register any custom importers or processors.
            foreach (string pipelineAssembly in pipelineAssemblies)
            {
                msBuildProject.AddNewItem("Reference", pipelineAssembly);
            }

            // Include the standard targets file that defines
            // how to build XNA Framework content.
            msBuildProject.AddNewImport("$(MSBuildExtensionsPath)\\Microsoft\\XNA " +
                                        "Game Studio\\v3.1\\Microsoft.Xna.GameStudio" +
                                        ".ContentPipeline.targets", null);
        }
开发者ID:pampersrocker,项目名称:STAR,代码行数:38,代码来源:ContentBuilder.cs

示例11: RemoveEvaluatedItemAfterExpansionFails

 public void RemoveEvaluatedItemAfterExpansionFails()
 {
     try
     {
         CompatibilityTestHelpers.CreateFiles(2, "foo", "foo", ObjectModelHelpers.TempProjectDir);
         Project p = new Project();
         object o = p.EvaluatedItems; // this causes failure
         p.AddNewItem("foos", Path.Combine(ObjectModelHelpers.TempProjectDir, "*.foo"));
         p.RemoveItem(p.EvaluatedItems[0]);   // Exception thrown here
         Assertion.Fail("success as failure"); // should not get here due to exception above
     }
     catch (Exception e)
     {
         // ExpectedException cannot be asserted as InternalErrorExceptions are internally scoped.
         Assertion.AssertEquals(true, e.GetType().ToString().Contains("InternalErrorException"));
     }
     finally
     {
         CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:21,代码来源:Project_Tests.cs

示例12: AddNewItemName_Null

 public void AddNewItemName_Null()
 {
     Project p = new Project();
     p.AddNewItem(null, "include");
 }
开发者ID:nikson,项目名称:msbuild,代码行数:5,代码来源:Project_Tests.cs

示例13: RemoveItem_IsNotImported

 public void RemoveItem_IsNotImported()
 {
     Project p = new Project();
     Project i = new Project(p.ParentEngine);
     BuildItem buildItem = i.AddNewItem("n", "i");
     p.RemoveItem(buildItem);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:7,代码来源:Project_Tests.cs

示例14: RemoveItemDirtyAfterRemove

 public void RemoveItemDirtyAfterRemove()
 {
     string projectPath  = ObjectModelHelpers.CreateFileInTempProjectDirectory("save.proj", String.Empty);
     try
     {
         Project p = new Project();
         BuildItem buildItem = p.AddNewItem("n", "i");
         p.Save(projectPath);
         Assertion.AssertEquals(false, p.IsDirty);
         p.RemoveItem(buildItem);
         Assertion.AssertEquals(true, p.IsDirty);
     }
     finally
     {
         CompatibilityTestHelpers.RemoveFile(projectPath);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:17,代码来源:Project_Tests.cs

示例15: RemoveItem

 public void RemoveItem()
 {
     Project p = new Project();
     BuildItem buildItem1 = p.AddNewItem("n", "i", true);
     Assertion.AssertNotNull(CompatibilityTestHelpers.FindBuildItem(p, "n"));
     p.RemoveItem(buildItem1);
     Assertion.AssertNull(CompatibilityTestHelpers.FindBuildItem(p, "n"));
 }
开发者ID:nikson,项目名称:msbuild,代码行数:8,代码来源:Project_Tests.cs


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