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


C# Project.Build方法代码示例

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


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

示例1: CompileProject

        public Assembly CompileProject(string projectFileName)
        {
            Assembly existing;
            if (Compilations.TryGetValue(Path.GetFullPath(projectFileName), out existing))
            {
                return existing;
            }

            var project = new Microsoft.Build.BuildEngine.Project();
            project.Load(projectFileName);

            var projectName = Environment.NameTable.GetNameFor(project.EvaluatedProperties["AssemblyName"].Value);
            var projectPath = project.FullFileName;
            var compilerOptions = new SpecSharpOptions();
            var assemblyReferences = new List<IAssemblyReference>();
            var moduleReferences = new List<IModuleReference>();
            var programSources = new List<SpecSharpSourceDocument>();
            var assembly = new SpecSharpAssembly(projectName, projectPath, Environment, compilerOptions, assemblyReferences, moduleReferences, programSources);
            var helper = new SpecSharpCompilationHelper(assembly.Compilation);

            Compilations[Path.GetFullPath(projectFileName)] = assembly;

            assemblyReferences.Add(Environment.LoadAssembly(Environment.CoreAssemblySymbolicIdentity));
            project.Build("ResolveAssemblyReferences");
            foreach (BuildItem item in project.GetEvaluatedItemsByName("ReferencePath"))
            {
                var assemblyName = new System.Reflection.AssemblyName(item.GetEvaluatedMetadata("FusionName"));
                var name = Environment.NameTable.GetNameFor(assemblyName.Name);
                var culture = assemblyName.CultureInfo != null ? assemblyName.CultureInfo.Name : "";
                var version = assemblyName.Version == null ? new Version(0, 0) : assemblyName.Version;
                var token = assemblyName.GetPublicKeyToken();
                if (token == null) token = new byte[0];
                var location = item.FinalItemSpec;
                var identity = new AssemblyIdentity(name, culture, version, token, location);
                var reference = Environment.LoadAssembly(identity);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("ProjectReference"))
            {
                var name = Environment.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(item.FinalItemSpec));
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var reference = CompileProject(location);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("Compile"))
            {
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var name = Environment.NameTable.GetNameFor(location);
                var programSource = new SpecSharpSourceDocument(helper, name, location, File.ReadAllText(location));
                programSources.Add(programSource);
            }

            return assembly;
        }
开发者ID:dbremner,项目名称:specsharp,代码行数:56,代码来源:MSBuildCompiler.cs

示例2: TestHintPath1

		public void TestHintPath1 ()
		{
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (ResolveAssembly (null, @"Test\resources\test.dll"));
			
			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:ResolveAssemblyReferenceTest.cs

示例3: ResolveBinary_FancyStuff

		public void ResolveBinary_FancyStuff ()
		{
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\FancyStuff.dll"));
			
			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big[0].Include.EndsWith ("FancyStuff.dll"), "A3");
			
			big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
			Assert.AreEqual (1, big.Count, "A4");
			Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:15,代码来源:ResolveAssemblyReferenceTest.cs

示例4: TestGac1

		public void TestGac1 ()
		{
			var gacDir = GetGacDir ();

			if (gacDir == null || !System.IO.Directory.Exists (gacDir))
				Assert.Ignore ("GAC not found.");

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (ResolveAssembly ("System", null));
			
			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:ResolveAssemblyReferenceTest.cs

示例5: TestGac1

		public void TestGac1 ()
		{
			string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<ItemGroup>
						<Reference Include='System' />
					</ItemGroup>
					<PropertyGroup>
						<SearchPaths>
							{CandidateAssemblyFiles};
							$(ReferencePath);
							{HintPathFromItem};
							{TargetFrameworkDirectory};
							{AssemblyFolders};
							{GAC};
							{RawFileName};
							$(OutputPath)
						</SearchPaths>
					</PropertyGroup>
					<Target Name='A'>
						<ResolveAssemblyReference
							Assemblies='@(Reference)'
							SearchPaths='$(SearchPaths)'
						>
							<Output TaskParameter='ResolvedFiles' ItemName='ResolvedFiles'/>
						</ResolveAssemblyReference>
					</Target>
				</Project>
			";
			
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);

			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:39,代码来源:ResolveAssemblyReferenceTest.cs

示例6: ProjectBuiltUsingMSBuildTaskShouldBuildUsingDefaultToolsVersionIfOneIsNotSpecified

        public void ProjectBuiltUsingMSBuildTaskShouldBuildUsingDefaultToolsVersionIfOneIsNotSpecified()
        {
            try
            {
                string projectContent =
                    @"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`a`>
                        <Message Text=`[a=$(MSBuildToolsVersion)]`/>
                        <MSBuild Projects=`p2.proj`/>
                    </Target>
                    </Project>
                    ";
                string projectContent2 =
                    @"
                    <Project xmlns=`msbuildnamespace`>
                    <Target Name=`a`>
                        <Message Text=`[b=$(MSBuildToolsVersion)]`/>
                    </Target>
                    </Project>
                    ";

                MockLogger logger = new MockLogger();
                Engine e = new Engine();
                e.RegisterLogger(logger);

                string p1Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p1.proj", projectContent);
                string p2Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p2.proj", projectContent2);

                Project p1 = new Project(e);
                p1.Load(p1Path);
                p1.Build();

                logger.AssertLogContains("[a="+ ObjectModelHelpers.MSBuildDefaultToolsVersion + "]");
                Assertion.Assert("Cachescope should have an entry with 4.0", e.CacheManager.GetCacheScope(p1Path, new BuildPropertyGroup(), ObjectModelHelpers.MSBuildDefaultToolsVersion, CacheContentType.BuildResults) != null);
                Assertion.Assert("Cachescope should have an entry with default tools version", e.CacheManager.GetCacheScope(p2Path, new BuildPropertyGroup(), e.DefaultToolsVersion, CacheContentType.BuildResults) != null);

            }
            finally
            {
                ObjectModelHelpers.DeleteTempProjectDirectory();
            }
        }
开发者ID:nikson,项目名称:msbuild,代码行数:43,代码来源:Engine_Tests.cs

示例7: BuildProjectWithReservedGlobalProperty

        public void BuildProjectWithReservedGlobalProperty()
        {
            string childProject = ObjectModelHelpers.CreateTempFileOnDisk(@"
                <Project xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`>
                    <Target Name=`1`></Target>
                 </Project>
            ");

            string mainProject = ObjectModelHelpers.CreateTempFileOnDisk(@"
                <Project xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`>
                    <Target Name=`1`>
                        <MSBuild Projects=`@(ProjectReference)`/>
                    </Target>
                    <ItemGroup>
                        <ProjectReference Include=`{0}`><Properties>Target=1</Properties></ProjectReference>
                    </ItemGroup>
                 </Project>
                 ", childProject);

            ProjectIdLogger logger = new ProjectIdLogger();
            Engine engine = new Engine();
            engine.RegisterLogger(logger);

            Project project = new Project(engine, "4.0");
            project.Load(mainProject);

            bool success = project.Build(null, null);
            Assertion.Assert("Build succeded and should have failed.  See Standard Out tab for details", !success);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:29,代码来源:Engine_Tests.cs

示例8: TestImportEmptyVariableWithConditionFalse

		public void TestImportEmptyVariableWithConditionFalse ()
		{
			string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
				<Import Project='$(ImportPath)' Condition='false' />
				<Target Name='Build' />
			</Project>";

			engine = new Engine (Consts.BinPath);

			project = engine.CreateNewProject ();
			project.LoadXml (documentString);

			Assert.IsTrue (project.Build ("Build"), "Build failed");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:14,代码来源:ImportTest.cs

示例9: TestExecution1

		public void TestExecution1 ()
		{
			string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<Target Name='1'>
						<Error Text='Text' HelpKeyword='HelpKeyword' Code='Code' />
					</Target>
				</Project>
			";
			
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);

			bool result = project.Build ("1");

			Assert.AreEqual (false, result, "#1");
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:18,代码来源:ErrorTest.cs

示例10: BuildProject

 public bool BuildProject(Project project)
 {
     if (project == null)
         throw new ArgumentException ("project");
     builtTargetsOutputByName.Clear ();
     return project.Build ();
 }
开发者ID:Jedzia,项目名称:BackBock,代码行数:7,代码来源:Engine.cs

示例11: TestTargetReturns

		public void TestTargetReturns ()
		{
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.Load (Path.Combine ("Test", Path.Combine ("resources", "TestReturns.csproj")));

			var logger = new TestMessageLogger ();
			engine.RegisterLogger (logger);

			bool result = project.Build ("Main");
			if (!result) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.CheckLoggedMessageHead ("Result: Bar", "A1");

			Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found");
		}
开发者ID:ancailliau,项目名称:mono,代码行数:19,代码来源:TargetTest.cs

示例12: TestLazyLoad2

		public void TestLazyLoad2 ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='Another.SameTask'
					/>
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='Other.SameTask'
					/>

					<Target Name='1'>
						<Other.SameTask>
							<Output TaskParameter='OutputString' ItemName='I0'/>
						</Other.SameTask>
						<Another.SameTask>
							<Output TaskParameter='OutputString' ItemName='I1'/>
						</Another.SameTask>
						<Message Text='I0: @(I0) I1: @(I1)'/>
					</Target>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			project.LoadXml (documentString);

			if (!project.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.CheckLoggedMessageHead ("I0: Other.SameTask I1: Another.SameTask", "A1");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:40,代码来源:UsingTaskTest.cs

示例13: TestLazyLoad1

		public void TestLazyLoad1 ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask
						AssemblyFile='NonExistantAssembly.dll'
						TaskName='SimpleTask'
					/>
					<Target Name='1'>
						<Message Text='hello'/>
					</Target>
					<Target Name='2'>
						<SimpleTask Foo='bar'/>
					</Target>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			project.LoadXml (documentString);

			if (!project.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			if (project.Build ("2"))
				Assert.Fail ("Build should've failed, as a task from a nonexistant assembly is referenced");


			IEnumerator en = project.UsingTasks.GetEnumerator ();
			en.MoveNext ();

			UsingTask ut = (UsingTask) en.Current;

			Assert.AreEqual ("NonExistantAssembly.dll", ut.AssemblyFile, "A1");
			Assert.IsNull (ut.AssemblyName, "A2");
			Assert.AreEqual (null, ut.Condition, "A3");
			Assert.AreEqual (false, ut.IsImported, "A4");
			Assert.AreEqual ("SimpleTask", ut.TaskName, "A5");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:45,代码来源:UsingTaskTest.cs

示例14: TestDuplicate1

		public void TestDuplicate1 ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='TrueTestTask'
					/>
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='TrueTestTask'
					/>

					<Target Name='1'>
						<TrueTestTask/>
					</Target>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			project.LoadXml (documentString);

			if (!project.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			Assert.AreEqual (2, project.UsingTasks.Count, "A0");

			foreach (UsingTask ut in project.UsingTasks) {
				Assert.AreEqual ("Test/resources/TestTasks.dll", ut.AssemblyFile, "A1");
				Assert.IsNull (ut.AssemblyName, "A2");
				Assert.AreEqual (null, ut.Condition, "A3");
				Assert.AreEqual (false, ut.IsImported, "A4");
				Assert.AreEqual ("TrueTestTask", ut.TaskName, "A5");
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:42,代码来源:UsingTaskTest.cs

示例15: TestExecution

		public void TestExecution ()
		{
			string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<Target Name='1'>
						<Message Text='Text1' Importance='Low'/>
						<Message Text='Text2' Importance='Normal'/>
						<Message Text='Text3' Importance='High'/>
						<Message Text='Text4' Importance='low'/>
						<Message Text='Text5' Importance='normal'/>
						<Message Text='Text6' Importance='high'/>
						<Message Text='Text7' />
						<Message Text='Text8' Importance='weird_importance'/>
					</Target>
				</Project>
			";
			
			engine = new Engine (Consts.BinPath);
			testLogger = new TestMessageLogger ();
			engine.RegisterLogger (testLogger);
			
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);
			if (project.Build ("1")) {
				testLogger.DumpMessages ();
				Assert.Fail ("Build should have failed");
			}
			
			Assert.AreEqual (0, testLogger.CheckAny ("Text1", MessageImportance.Low), "A1");
			Assert.AreEqual (0, testLogger.CheckAny ("Text2", MessageImportance.Normal), "A2");
			Assert.AreEqual (0, testLogger.CheckAny ("Text3", MessageImportance.High), "A3");
			Assert.AreEqual (0, testLogger.CheckAny ("Text4", MessageImportance.Low), "A4");
			Assert.AreEqual (0, testLogger.CheckAny ("Text5", MessageImportance.Normal), "A5");
			Assert.AreEqual (0, testLogger.CheckAny ("Text6", MessageImportance.High), "A6");
			Assert.AreEqual (0, testLogger.CheckAny ("Text7", MessageImportance.Normal), "A7");
			Assert.AreEqual (1, testLogger.CheckAny ("Text8", MessageImportance.Normal), "A8");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:37,代码来源:MessageTest.cs


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