本文整理汇总了C#中Microsoft.Build.Evaluation.Project.CreateProjectInstance方法的典型用法代码示例。如果您正苦于以下问题:C# Project.CreateProjectInstance方法的具体用法?C# Project.CreateProjectInstance怎么用?C# Project.CreateProjectInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.Project
的用法示例。
在下文中一共展示了Project.CreateProjectInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProjectInstancePassesEnvironment
public void CreateProjectInstancePassesEnvironment()
{
Project p = new Project();
ProjectInstance i = p.CreateProjectInstance();
Assert.Equal(true, i.GetPropertyValue("username") != null);
}
示例2: GetMetadataInstance
/// <summary>
/// Get a single metadata instance
/// </summary>
private static ProjectMetadataInstance GetMetadataInstance()
{
Project project = new Project();
ProjectInstance projectInstance = project.CreateProjectInstance();
ProjectItemInstance item = projectInstance.AddItem("i", "i1");
ProjectMetadataInstance metadata = item.SetMetadata("m", "m1");
return metadata;
}
示例3: TargetOverride_Escaped
public void TargetOverride_Escaped()
{
ProjectRootElement projectXml = ProjectRootElement.Create();
projectXml.AddTarget("t%3b").Inputs = "i1";
projectXml.AddTarget("t;").Inputs = "i2";
Project project = new Project(projectXml);
ProjectInstance instance = project.CreateProjectInstance();
ProjectTargetInstance target = instance.Targets["t;"];
Assert.Equal("i2", target.Inputs);
}
示例4: CreateEmptyProjectInstance
/// <summary>
/// Creates a project instance with a single empty target named 'foo'
/// </summary>
/// <returns>A project instance.</returns>
internal static ProjectInstance CreateEmptyProjectInstance()
{
XmlReader reader = XmlReader.Create(new StringReader
(
@"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' ToolsVersion='4.0'>
<Target Name='foo'/>
</Project>"
));
Project project = new Project(reader);
ProjectInstance instance = project.CreateProjectInstance();
return instance;
}
示例5: GetTaskInstance
/// <summary>
/// Return a task instance representing the task XML string passed in
/// </summary>
private static ProjectTaskInstance GetTaskInstance(string taskXmlString)
{
string content = @"
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
<Target Name='t'>
" + taskXmlString + @"
</Target>
</Project>
";
ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
Project project = new Project(xml);
ProjectInstance instance = project.CreateProjectInstance();
ProjectTaskInstance task = (ProjectTaskInstance)(instance.Targets["t"].Children[0]);
return task;
}
示例6: GetSampleOnErrorInstance
/// <summary>
/// Create a TaskInstance with some parameters
/// </summary>
private static ProjectOnErrorInstance GetSampleOnErrorInstance()
{
string content = @"
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
<Target Name='t'>
<OnError ExecuteTargets='et' Condition='c'/>
</Target>
</Project>
";
ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
Project project = new Project(xml);
ProjectInstance instance = project.CreateProjectInstance();
ProjectOnErrorInstance onError = (ProjectOnErrorInstance)instance.Targets["t"].OnErrorChildren[0];
return onError;
}
示例7: GetSampleTaskOutputInstance
/// <summary>
/// Create a ProjectTaskOutputPropertyInstance with some parameters
/// </summary>
private static ProjectTaskOutputPropertyInstance GetSampleTaskOutputInstance()
{
string content = @"
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
<Target Name='t'>
<t1>
<Output TaskParameter='p' Condition='c' PropertyName='p1'/>
</t1>
</Target>
</Project>
";
ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
Project project = new Project(xml);
ProjectInstance instance = project.CreateProjectInstance();
ProjectTaskInstance task = (ProjectTaskInstance)instance.Targets["t"].Children[0];
ProjectTaskOutputPropertyInstance output = (ProjectTaskOutputPropertyInstance)task.Outputs[0];
return output;
}
示例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: BuildAndAnalyze
public void BuildAndAnalyze()
{
var globalProps = new Dictionary<string, string> {
{"VisualStudioVersion","12.0"}
};
pc = new ProjectCollection(globalProps);
var diagLogger = new DiagnosticXmlLogger(this);
diagLogger.LogFile = _logFilepath;
project = pc.LoadProject(_projectFilepath, "12.0");
projInst = project.CreateProjectInstance();
buildManager = new BuildManager();
var buildParams = new BuildParameters();
buildParams.Loggers = new ILogger[] { diagLogger };
buildManager.BeginBuild(buildParams);
var brd = new BuildRequestData(projInst, _targets, null, BuildRequestDataFlags.ReplaceExistingProjectInstance);
submission = buildManager.PendBuildRequest(brd);
buildResult = submission.Execute();
buildManager.EndBuild();
}
示例10: AddMetadata_EscapedValue
public void AddMetadata_EscapedValue()
{
Project project = new Project();
ProjectItem item = project.AddItem("i", "i1")[0];
item.SetMetadataValue("m", "m1%24%24");
string expected = ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<ItemGroup>
<i Include=""i1"">
<m>m1%24%24</m>
</i>
</ItemGroup>
</Project>");
Helpers.VerifyAssertProjectContent(expected, project.Xml);
List<ProjectItem> items = Helpers.MakeList(project.Items);
Assert.Equal("m1$$", items[0].GetMetadataValue("m"));
Assert.Equal("m1$$", Helpers.MakeList(project.CreateProjectInstance().GetItems("i"))[0].GetMetadataValue("m"));
}
示例11: TestSetProjectGood
public void TestSetProjectGood()
{
BuildRequestData data1 = new BuildRequestData("file", new Dictionary<string, string>(), "toolsVersion", new string[0], null);
BuildRequestConfiguration config1 = new BuildRequestConfiguration(data1, "2.0");
Assert.Null(config1.Project);
Project project = new Project(XmlReader.Create(new StringReader(ObjectModelHelpers.CleanupFileContents(@"<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace' />"))));
ProjectInstance projectInstance = project.CreateProjectInstance();
config1.Project = projectInstance;
Assert.Same(config1.Project, projectInstance);
}
示例12: SetProperty_EscapedValue
public void SetProperty_EscapedValue()
{
Project project = new Project();
int environmentPropertyCount = Helpers.MakeList(project.Properties).Count;
project.SetProperty("p1", "v%5E1");
string expected = ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
<PropertyGroup>
<p1>v%5E1</p1>
</PropertyGroup>
</Project>");
Helpers.VerifyAssertProjectContent(expected, project.Xml);
Assert.Equal("v^1", project.GetPropertyValue("p1"));
Assert.Equal("v^1", project.CreateProjectInstance().GetPropertyValue("p1"));
Assert.Equal(1, Helpers.Count(project.Properties) - environmentPropertyCount);
}
示例13: RemoveProperty
public void RemoveProperty()
{
Project project = new Project();
int environmentPropertyCount = Helpers.MakeList(project.Properties).Count;
project.SetProperty("p1", "v1");
project.ReevaluateIfNecessary();
project.RemoveProperty(project.GetProperty("p1"));
string expected = ObjectModelHelpers.CleanupFileContents(@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"" />");
Helpers.VerifyAssertProjectContent(expected, project.Xml);
Assert.Equal(null, project.GetProperty("p1"));
ProjectInstance instance = project.CreateProjectInstance();
Assert.Equal(String.Empty, instance.GetPropertyValue("p1"));
Assert.Equal(0, Helpers.Count(project.Properties) - environmentPropertyCount);
}
示例14: ITaskItem2Operations
public void ITaskItem2Operations()
{
Project project = new Project();
ProjectInstance projectInstance = project.CreateProjectInstance();
ProjectItemInstance item = projectInstance.AddItem("EscapedItem", "esca%20ped%3bitem");
item.SetMetadata("m", "m1");
item.SetMetadata("m;", "m%3b1");
ITaskItem2 taskItem = (ITaskItem2)item;
Assert.Equal(taskItem.EvaluatedIncludeEscaped, "esca%20ped%3bitem");
Assert.Equal(taskItem.ItemSpec, "esca ped;item");
Assert.Equal(taskItem.GetMetadata("m;"), "m;1");
Assert.Equal(taskItem.GetMetadataValueEscaped("m;"), "m%3b1");
Assert.Equal(taskItem.GetMetadataValueEscaped("m"), "m1");
Assert.Equal(taskItem.EvaluatedIncludeEscaped, "esca%20ped%3bitem");
Assert.Equal(taskItem.ItemSpec, "esca ped;item");
ITaskItem2 taskItem2 = new Microsoft.Build.Utilities.TaskItem(taskItem);
taskItem2.SetMetadataValueLiteral("m;", "m;2");
Assert.Equal(taskItem2.GetMetadataValueEscaped("m;"), "m%3b2");
Assert.Equal(taskItem2.GetMetadata("m;"), "m;2");
IDictionary<string, string> taskItem2Metadata = (IDictionary<string, string>)taskItem2.CloneCustomMetadata();
Assert.Equal(3, taskItem2Metadata.Count);
foreach (KeyValuePair<string, string> pair in taskItem2Metadata)
{
if (pair.Key.Equals("m"))
{
Assert.Equal("m1", pair.Value);
}
if (pair.Key.Equals("m;"))
{
Assert.Equal("m;2", pair.Value);
}
if (pair.Key.Equals("OriginalItemSpec"))
{
Assert.Equal("esca ped;item", pair.Value);
}
}
IDictionary<string, string> taskItem2MetadataEscaped = (IDictionary<string, string>)taskItem2.CloneCustomMetadataEscaped();
Assert.Equal(3, taskItem2MetadataEscaped.Count);
foreach (KeyValuePair<string, string> pair in taskItem2MetadataEscaped)
{
if (pair.Key.Equals("m"))
{
Assert.Equal("m1", pair.Value);
}
if (pair.Key.Equals("m;"))
{
Assert.Equal("m%3b2", pair.Value);
}
if (pair.Key.Equals("OriginalItemSpec"))
{
Assert.Equal("esca%20ped%3bitem", pair.Value);
}
}
}
示例15: GetPropertyInstance
/// <summary>
/// Get a ProjectPropertyInstance
/// </summary>
private static ProjectPropertyInstance GetPropertyInstance()
{
Project project = new Project();
ProjectInstance projectInstance = project.CreateProjectInstance();
ProjectPropertyInstance property = projectInstance.SetProperty("p", "v1");
return property;
}