本文整理汇总了C#中Microsoft.Build.Execution.ProjectInstance.Build方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectInstance.Build方法的具体用法?C# ProjectInstance.Build怎么用?C# ProjectInstance.Build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Execution.ProjectInstance
的用法示例。
在下文中一共展示了ProjectInstance.Build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OutputPropertyExists
public void OutputPropertyExists ()
{
string project_xml = @"
<Project DefaultTargets='Build' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<C>False</C>
</PropertyGroup>
<Target Name='Build' DependsOnTargets='ResolveReferences' />
<Target Name='Build2' DependsOnTargets='Bar' />
<Target Name='ResolveReferences' DependsOnTargets='Foo;Bar' />
<Target Name='Foo'>
<CreateProperty Value='True'>
<Output TaskParameter='Value' PropertyName='C' />
</CreateProperty>
</Target>
<Target Name='Bar' Condition='!($(C))' DependsOnTargets='ResolveReferences'>
</Target>
</Project>";
var xml = XmlReader.Create (new StringReader(project_xml));
var root = ProjectRootElement.Create (xml);
var proj = new ProjectInstance (root);
Assert.AreEqual (5, proj.Targets.Count, "#1");
var foo = proj.Targets ["Foo"];
Assert.IsNotNull (foo, "#2");
Assert.AreEqual (1, foo.Tasks.Count, "#3");
var cp = foo.Tasks.First ();
Assert.AreEqual (1, cp.Outputs.Count, "#4");
var po = cp.Outputs.First () as ProjectTaskOutputPropertyInstance;
Assert.IsNotNull (po, "#5");
Assert.AreEqual ("C", po.PropertyName, "#5");
proj.Build ("Build", null);
Assert.AreEqual (string.Empty, foo.Outputs, "#6");
Assert.AreEqual ("True", proj.GetPropertyValue ("C"), "#7");
}
示例2: BuildDoesNotIncreaseCollectionContent
public void BuildDoesNotIncreaseCollectionContent ()
{
string empty_project_xml = "<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
var xml = XmlReader.Create (new StringReader (empty_project_xml));
var root = ProjectRootElement.Create (xml);
var coll = new ProjectCollection ();
var inst = new ProjectInstance (root, null, null, coll);
root.FullPath = "ProjectCollectionTest.BuildDoesNotIncreaseCollectionContent.proj";
Assert.AreEqual (0, coll.Count, "#1");
inst.Build ();
Assert.AreEqual (0, coll.Count, "#2");
}
示例3: TaskOutputsToLoggers
public void TaskOutputsToLoggers ()
{
string project_xml = @"<Project DefaultTargets='Foo' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Import Project='$(MSBuildToolsPath)\Microsoft.Common.targets' />
<Target Name='Foo'>
<ItemGroup>
<Foo Condition='$(X)' Include='foo.txt' />
</ItemGroup>
</Target>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "BuildSubmissionTest.TaskOutputsToLoggers.proj";
var proj = new ProjectInstance (root);
Assert.AreEqual ("$(X)", root.Targets.First ().ItemGroups.First ().Items.First ().Condition, "#0");
var sw = new StringWriter ();
Assert.IsFalse (proj.Build (new ILogger [] {new ConsoleLogger (LoggerVerbosity.Diagnostic, sw.WriteLine, null, null)}), "#1");
Assert.IsTrue (sw.ToString ().Contains ("$(X)"), "#2");
}
示例4: TestResolveProjectHome
public void TestResolveProjectHome() {
var proj = ProjectRootElement.Create();
var g = proj.AddPropertyGroup();
var projectHome = g.AddProperty("ProjectHome", "");
var expected = g.AddProperty("Expected", "");
g.AddProperty("StartupFile", "app.py");
g.AddProperty("_PythonToolsPath", TestData.GetPath(""));
proj.AddImport(TestData.GetPath("Microsoft.PythonTools.targets"));
var target = proj.AddTarget("TestOutput");
foreach (var variable in new[] { "ProjectHome", "QualifiedProjectHome", "StartupFile", "StartupPath", "Expected" }) {
var task = target.AddTask("Message");
task.SetParameter("Importance", "high");
task.SetParameter("Text", string.Format("{0} = $({0})", variable));
}
var errTask = target.AddTask("Error");
errTask.Condition = "$(Expected) != $(QualifiedProjectHome)";
errTask.SetParameter("Text", "Expected did not match QualifiedProjectHome");
var loc = CommonUtils.EnsureEndSeparator(TestData.GetTempPath(randomSubPath: true));
proj.Save(Path.Combine(loc, string.Format("test.proj")));
foreach(var test in new [] {
new { ProjectHome="", Expected=loc },
new { ProjectHome=".", Expected=loc },
new { ProjectHome="..", Expected=CommonUtils.EnsureEndSeparator(Path.GetDirectoryName(Path.GetDirectoryName(loc))) },
new { ProjectHome="\\", Expected=Directory.GetDirectoryRoot(loc) },
new { ProjectHome="abc", Expected=loc + @"abc\" },
new { [email protected]"a\b\c", Expected=loc + @"a\b\c\" },
new { [email protected]"a\b\..\c", Expected=loc + @"a\c\" },
}) {
projectHome.Value = test.ProjectHome;
expected.Value = test.Expected;
var inst = new ProjectInstance(proj);
Assert.IsTrue(inst.Build("TestOutput", new ILogger[] { new ConsoleLogger(LoggerVerbosity.Detailed) }));
}
}
示例5: DependsOnTargets
public void DependsOnTargets ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Bar' DependsOnTargets='Foo' />
<Target Name='Foo'>
<Error Text='expected error' />
</Target>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectInstanceTest.DependsOnTargets.proj";
var proj = new ProjectInstance (root);
Assert.AreEqual (2, proj.Targets.Count, "#1");
Assert.IsFalse (proj.Build ("Bar", new ILogger [0]), "#2");
}
示例6: ItemsInTargets
[Category ("NotWorking")] // until we figure out why it fails on wrench.
public void ItemsInTargets ()
{
string project_xml = @"<Project DefaultTargets='Default' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Default'>
<PropertyGroup>
<_ExplicitMSCorlibPath>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries ('$(TargetFrameworkIdentifier)', '$(TargetFrameworkVersion)', '$(TargetFrameworkProfile)'))\mscorlib.dll</_ExplicitMSCorlibPath>
</PropertyGroup>
<ItemGroup>
<_ExplicitReference
Include='$(_ExplicitMSCorlibPath)'
Condition='Exists($(_ExplicitMSCorlibPath))'>
<Private>false</Private>
</_ExplicitReference>
</ItemGroup>
</Target>
<Import Project='$(MSBuildBinPath)\\Microsoft.CSharp.targets' />
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectInstanceTest.ConditionalExpression.proj";
var proj = new ProjectInstance (root, null, "4.0", ProjectCollection.GlobalProjectCollection);
proj.Build ();
// make sure the property value expansion is done successfully.
Assert.IsTrue (!string.IsNullOrEmpty (proj.GetPropertyValue ("_ExplicitMSCorlibPath")), "premise: propertyValue by ToolLocationHelper func call");
var items = proj.GetItems ("_ExplicitReference");
// make sure items are stored after build.
Assert.IsTrue (items.Any (), "items.Any");
Assert.IsTrue (!string.IsNullOrEmpty (items.First ().EvaluatedInclude), "item.EvaluatedInclude");
}
示例7: TestResolveEnvironmentReference
public void TestResolveEnvironmentReference() {
var proj = new ProjectInstance(TestData.GetPath(@"TestData\Targets\EnvironmentReferences1.pyproj"));
Assert.IsTrue(proj.Build("TestResolveEnvironment", new ILogger[] { new ConsoleLogger(LoggerVerbosity.Detailed) }));
}
示例8: TestCommandDefinitions
public void TestCommandDefinitions() {
var proj = new ProjectInstance(TestData.GetPath(@"TestData\Targets\Commands1.pyproj"));
Assert.IsTrue(proj.Build("TestCommands", new ILogger[] { new ConsoleLogger(LoggerVerbosity.Detailed) }));
}
示例9: FunctionCall
public void FunctionCall ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Foo'>
<Warning Text=""$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries ('$(TargetFrameworkIdentifier)', '$(TargetFrameworkVersion)', '$(TargetFrameworkProfile)'))\mscorlib.dll'"" />
</Target>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
var p = new ProjectInstance (root, null, "4.0", ProjectCollection.GlobalProjectCollection);
var sw = new StringWriter ();
var result = p.Build (new ILogger [] { new ConsoleLogger (LoggerVerbosity.Minimal, sw.WriteLine, null, null)});
Assert.IsTrue (result, "#1: " + sw);
}
示例10: MetadataExpansion
public void MetadataExpansion ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<X>a/b/c.txt</X>
</PropertyGroup>
<Target Name='Foo'>
<CreateItem Include='$(X)'>
<Output TaskParameter='Include' ItemName='I' />
</CreateItem>
<CreateProperty Value=""@(I->'%(Filename)%(Extension)')"">
<Output TaskParameter='Value' PropertyName='P' />
</CreateProperty>
<Error Text=""Expected 'c.txt' but got '$(P)'"" Condition=""'$(P)'!='c.txt'"" />
</Target>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
var p = new ProjectInstance (root);
var sw = new StringWriter ();
var result = p.Build (new ILogger [] { new ConsoleLogger (LoggerVerbosity.Minimal, sw.WriteLine, null, null)});
Assert.IsTrue (result, "#1: " + sw);
}
示例11: InvalidToolsVersionFromEnvironmentVariable_ProjectInstance
public void InvalidToolsVersionFromEnvironmentVariable_ProjectInstance()
{
string oldDefaultToolsVersion = Environment.GetEnvironmentVariable("MSBUILDDEFAULTTOOLSVERSION");
try
{
Environment.SetEnvironmentVariable("MSBUILDDEFAULTTOOLSVERSION", "foo");
InternalUtilities.RefreshInternalEnvironmentValues();
ProjectCollection p = new ProjectCollection();
MockLogger mockLogger = new MockLogger();
LoggingService service = (LoggingService)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
service.RegisterLogger(mockLogger);
bool success = false;
Project project = new Project(XmlReader.Create(new StringReader(@"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Foo'>
</Target>
</Project>")), null /* no global properties */, null /* don't explicitly set the toolsversion */, p);
ProjectInstance pi = new ProjectInstance(project.Xml, null /* no global properties */, null /* don't explicitly set the toolsversion */, p);
success = pi.Build(new ILogger[] { mockLogger });
Assert.IsTrue(success);
mockLogger.AssertLogContains("ToolsVersion=\"4.0\"");
// falls back to the current ToolsVersion
mockLogger.AssertLogContains(ObjectModelHelpers.CleanupFileContents("ToolsVersion=\"msbuilddefaulttoolsversion\""));
}
finally
{
Environment.SetEnvironmentVariable("MSBUILDDEFAULTTOOLSVERSION", oldDefaultToolsVersion);
InternalUtilities.RefreshInternalEnvironmentValues();
}
}
示例12: BuildNullRemoteLoggerInArray
public void BuildNullRemoteLoggerInArray()
{
ProjectInstance instance = new ProjectInstance(ProjectRootElement.Create());
instance.Build("t", null, new ForwardingLoggerRecord[] { null });
}
示例13: BuildNullLoggerInArray
public void BuildNullLoggerInArray()
{
ProjectInstance instance = new ProjectInstance(ProjectRootElement.Create());
instance.Build("t", new ILogger[] { null });
}
示例14: BuildNullTargetInArray
public void BuildNullTargetInArray()
{
ProjectInstance instance = new ProjectInstance(ProjectRootElement.Create());
instance.Build(new string[] { null }, null);
}
示例15: PhoenixBatchingIssue
public void PhoenixBatchingIssue()
{
ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(ObjectModelHelpers.CleanupFileContents(@"
<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<ItemGroup>
<CppCompile Include='gen.cpp'/>
<CppCompile Include='def.cpp'>
<ObjectFile>def.obj</ObjectFile>
</CppCompile>
</ItemGroup>
<Target Name='t'>
<ItemGroup>
<CppCompile>
<IncludeInLib Condition=""'%(CppCompile.IncludeInLib)' == ''"">true</IncludeInLib>
</CppCompile>
<CppCompile>
<ObjectFile>%(Filename).obj</ObjectFile>
</CppCompile>
</ItemGroup>
</Target>
</Project>
"))));
ProjectInstance instance = new ProjectInstance(xml);
instance.Build();
Assert.AreEqual(2, instance.Items.Count());
Assert.AreEqual("gen.obj", instance.GetItems("CppCompile").First().GetMetadataValue("ObjectFile"));
Assert.AreEqual("def.obj", instance.GetItems("CppCompile").Last().GetMetadataValue("ObjectFile"));
}