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


C# ProjectInstance.Build方法代码示例

本文整理汇总了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");
		}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:34,代码来源:ProjectTaskInstanceTest.cs

示例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");
		}
开发者ID:frje,项目名称:SharpLang,代码行数:12,代码来源:ProjectCollectionTest.cs

示例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");
		}
开发者ID:GirlD,项目名称:mono,代码行数:19,代码来源:BuildSubmissionTest.cs

示例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) }));
            }
        }
开发者ID:sadapple,项目名称:PTVS,代码行数:39,代码来源:BuildTasksTests.cs

示例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");
		}
开发者ID:GirlD,项目名称:mono,代码行数:15,代码来源:ProjectTargetInstanceTest.cs

示例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");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:30,代码来源:ProjectInstanceTest.cs

示例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) }));
 }
开发者ID:sadapple,项目名称:PTVS,代码行数:4,代码来源:BuildTasksTests.cs

示例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) }));
 }
开发者ID:sadapple,项目名称:PTVS,代码行数:4,代码来源:BuildTasksTests.cs

示例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);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:14,代码来源:ExpressionParserTest.cs

示例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);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:23,代码来源:ExpressionParserTest.cs

示例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();
            }
        }
开发者ID:ravpacheco,项目名称:msbuild,代码行数:34,代码来源:ToolsVersion_Tests.cs

示例12: BuildNullRemoteLoggerInArray

 public void BuildNullRemoteLoggerInArray()
 {
     ProjectInstance instance = new ProjectInstance(ProjectRootElement.Create());
     instance.Build("t", null, new ForwardingLoggerRecord[] { null });
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:5,代码来源:ProjectInstance_Tests.cs

示例13: BuildNullLoggerInArray

 public void BuildNullLoggerInArray()
 {
     ProjectInstance instance = new ProjectInstance(ProjectRootElement.Create());
     instance.Build("t", new ILogger[] { null });
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:5,代码来源:ProjectInstance_Tests.cs

示例14: BuildNullTargetInArray

 public void BuildNullTargetInArray()
 {
     ProjectInstance instance = new ProjectInstance(ProjectRootElement.Create());
     instance.Build(new string[] { null }, null);
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:5,代码来源:ProjectInstance_Tests.cs

示例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"));
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:30,代码来源:IntrinsicTask_Tests.cs


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