本文整理汇总了C#中Microsoft.Build.Evaluation.Project.AddItem方法的典型用法代码示例。如果您正苦于以下问题:C# Project.AddItem方法的具体用法?C# Project.AddItem怎么用?C# Project.AddItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.Project
的用法示例。
在下文中一共展示了Project.AddItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddReference
private void AddReference(InputProjectDriver inputProjectDriver, Project project, string reference)
{
string referenceFullPath = Path.GetFullPath(Path.Combine(AssemblyFolderHelper.GetTestAssemblyFolder(), reference));
string assemblyName = Path.GetFileNameWithoutExtension(referenceFullPath);
Debug.Assert(assemblyName != null);
project.AddItem("Reference", assemblyName, new[]
{
new KeyValuePair<string, string>("HintPath", referenceFullPath),
});
}
示例2: ProjectGetter
public void ProjectGetter()
{
Project project = new Project();
ProjectItem item = project.AddItem("i", "i1")[0];
Assert.Equal(true, Object.ReferenceEquals(project, item.Project));
}
示例3: BuildProject
public static MSbuildResult BuildProject(MsBuildSettings settings, string projectFileName, DirectoryInfo dir)
{
var result = new MSbuildResult();
var path = Path.Combine(dir.FullName, projectFileName);
var project = new Project(path, null, null, new ProjectCollection());
project.SetProperty("CscToolPath", settings.CompilerDirectory.FullName);
var includes = new HashSet<string>(
project.AllEvaluatedItems
.Where(i => i.ItemType == "None" || i.ItemType == "Content")
.Select(i => Path.GetFileName(i.EvaluatedInclude.ToLowerInvariant())));
foreach (var dll in settings.WellKnownLibsDirectory.GetFiles("*.dll"))
if (!includes.Contains(dll.Name.ToLowerInvariant()))
project.AddItem("None", dll.FullName);
project.Save();
using (var stringWriter = new StringWriter())
{
var logger = new ConsoleLogger(LoggerVerbosity.Minimal, stringWriter.Write, color => { }, () => { });
result.Success = SyncBuild(project, logger);
if (result.Success)
result.PathToExe = Path.Combine(project.DirectoryPath,
project.GetPropertyValue("OutputPath"),
project.GetPropertyValue("AssemblyName") + ".exe");
else
result.ErrorMessage = stringWriter.ToString();
return result;
}
}
示例4: CreateBuildProject
void CreateBuildProject()
{
string projectPath = Path.Combine(buildDirectory, "content.contentproj");
string outputPath = Path.Combine(buildDirectory, "bin");
// Create the build project.
projectRootElement = ProjectRootElement.Create(projectPath);
// Include the standard targets file that defines how to build XNA Framework content.
projectRootElement.AddImport(Application.StartupPath + "\\Exporters\\FBX\\XNA\\XNA Game Studio\\" +
"v4.0\\Microsoft.Xna.GameStudio.ContentPipeline.targets");
buildProject = new Project(projectRootElement);
buildProject.SetProperty("XnaPlatform", "Windows");
buildProject.SetProperty("XnaProfile", "Reach");
buildProject.SetProperty("XnaFrameworkVersion", "v4.0");
buildProject.SetProperty("Configuration", "Release");
buildProject.SetProperty("OutputPath", outputPath);
buildProject.SetProperty("ContentRootDirectory", ".");
buildProject.SetProperty("ReferencePath", Application.StartupPath);
// Register any custom importers or processors.
foreach (string pipelineAssembly in pipelineAssemblies)
{
buildProject.AddItem("Reference", pipelineAssembly);
}
// Hook up our custom error logger.
errorLogger = new ErrorLogger();
buildParameters = new BuildParameters(ProjectCollection.GlobalProjectCollection)
{Loggers = new ILogger[] {errorLogger}};
}
示例5: ProjectGetter
public void ProjectGetter()
{
Project project = new Project();
ProjectItem item = project.AddItem("i", "i1")[0];
ProjectMetadata metadatum = item.SetMetadataValue("m", "m1");
Assert.AreEqual(true, Object.ReferenceEquals(project, metadatum.Project));
}
示例6: IncludeFileInCurrentProject
public static void IncludeFileInCurrentProject(string approved)
{
var p = new Project(GetCurrentProjectFile(approved));
if (!p.Items.Any(i => approved.EndsWith(i.UnevaluatedInclude)))
{
p.AddItem("Content", approved);
p.Save();
}
}
示例7: LinkToFile
public void LinkToFile(Project project, BuildAction buildAction, string includeValue, string projectTargetPath)
{
if(projectTargetPath.StartsWith("\\"))
throw new Exception("project target path cannot begin with a backslash");
var matchingProjectItemByTargetPath = (from t in project.Items
where
t.HasMetadata("Link") &&
t.GetMetadataValue("Link") == projectTargetPath
select t).SingleOrDefault();
if (matchingProjectItemByTargetPath != null)
project.RemoveItem(matchingProjectItemByTargetPath);
var buildActionName = Enum.GetName(typeof(BuildAction), buildAction);
project.AddItem(buildActionName, includeValue,
new[] {new KeyValuePair<string, string>("Link", projectTargetPath)});
}
示例8: 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);
}
示例9: SpecialCharactersInMetadataValueEvaluation
public void SpecialCharactersInMetadataValueEvaluation()
{
Project project = new Project();
ProjectItem item = project.AddItem("None", "MetadataTests", new Dictionary<string, string> {
{"EscapedSemicolon", "%3B"}, //Microsoft.Build.Evaluation.ProjectCollection.Escape(";")
{"EscapedDollarSign", "%24"}, //Microsoft.Build.Evaluation.ProjectCollection.Escape("$")
}).Single();
EscapingInProjectsHelper.SpecialCharactersInMetadataValueTests(item);
project.ReevaluateIfNecessary();
EscapingInProjectsHelper.SpecialCharactersInMetadataValueTests(item);
}
示例10: SettingItemIncludeDirties
public void SettingItemIncludeDirties()
{
Project project = new Project();
ProjectItem item = project.AddItem("i", "i1")[0];
project.ReevaluateIfNecessary();
item.Xml.Include = "i2";
project.ReevaluateIfNecessary();
Assert.Equal("i2", Helpers.GetFirst(project.Items).EvaluatedInclude);
}
示例11: ItemsByEvaluatedIncludeDirectAdd
public void ItemsByEvaluatedIncludeDirectAdd()
{
Project project = new Project();
project.AddItem("i", "i1");
List<ProjectItem> items = Helpers.MakeList(project.GetItemsByEvaluatedInclude("i1"));
Assert.Equal(1, items.Count);
}
示例12: SpecialCharactersInMetadataValueEvaluation
public void SpecialCharactersInMetadataValueEvaluation()
{
Microsoft.Build.Evaluation.Project project = new Microsoft.Build.Evaluation.Project();
var metadata = new Dictionary<string, string>
{
{ "EscapedSemicolon", "%3B" }, // Microsoft.Build.Internal.Utilities.Escape(";")
{ "EscapedDollarSign", "%24" }, // Microsoft.Build.Internal.Utilities.Escape("$")
};
Microsoft.Build.Evaluation.ProjectItem item = project.AddItem(
"None",
"MetadataTests",
metadata).Single();
SpecialCharactersInMetadataValueTests(item);
project.ReevaluateIfNecessary();
SpecialCharactersInMetadataValueTests(item);
}
示例13: SetValueWithPropertyExpression
public void SetValueWithPropertyExpression()
{
Project project = new Project();
project.SetProperty("p", "p0");
ProjectItem item = project.AddItem("i", "i1")[0];
ProjectMetadata metadatum = item.SetMetadataValue("m", "m1");
project.ReevaluateIfNecessary();
metadatum.UnevaluatedValue = "$(p)";
Assert.AreEqual("$(p)", metadatum.UnevaluatedValue);
Assert.AreEqual("p0", metadatum.EvaluatedValue);
}
示例14: AddItem_MatchesWildcardWithCondition
public void AddItem_MatchesWildcardWithCondition()
{
Project project = new Project();
ProjectItemElement itemElement = project.Xml.AddItem("i", "*.xxx");
itemElement.Condition = "true";
project.ReevaluateIfNecessary();
project.AddItem("i", "i1.xxx");
string expected = ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<ItemGroup>
<i Include=""*.xxx"" Condition=""true"" />
<i Include=""i1.xxx"" />
</ItemGroup>
</Project>");
Helpers.VerifyAssertProjectContent(expected, project);
}
示例15: AddItem_ContainingSemicolonExistingWildcard
public void AddItem_ContainingSemicolonExistingWildcard()
{
Project project = new Project();
project.Xml.AddItem("i", "*.xxx");
project.ReevaluateIfNecessary();
project.AddItem("i", "i1.xxx;i2.xxx");
string expected = ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<ItemGroup>
<i Include=""*.xxx"" />
<i Include=""i1.xxx;i2.xxx"" />
</ItemGroup>
</Project>");
Helpers.VerifyAssertProjectContent(expected, project);
}