本文整理汇总了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;
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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();
}
}
示例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);
}
示例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");
}
示例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");
}
示例10: BuildProject
public bool BuildProject(Project project)
{
if (project == null)
throw new ArgumentException ("project");
builtTargetsOutputByName.Clear ();
return project.Build ();
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
}
示例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");
}