本文整理汇总了C#中Microsoft.Build.Evaluation.Project.Build方法的典型用法代码示例。如果您正苦于以下问题:C# Project.Build方法的具体用法?C# Project.Build怎么用?C# Project.Build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.Project
的用法示例。
在下文中一共展示了Project.Build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Hello
public void Hello ()
{
string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<UsingTask
TaskName='DoNothing'
TaskFactory='CodeTaskFactory'
AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
<ParameterGroup />
<Task>
<Code Type='Fragment' Language='cs'>
<![CDATA[
// Display ""Hello, world!""
Log.LogWarning(""Hello, world!"");
]]> </Code>
</Task>
</UsingTask>
<Target Name='default'>
<DoNothing />
</Target>
</Project>";
var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
root.FullPath = "CodeTaskFactoryTest.Hello.proj";
var project = new Project (root);
Assert.IsTrue (project.Build (new ConsoleLogger (LoggerVerbosity.Diagnostic)), "Build");
}
示例2: VerifyNewLinesAndTabsEvaluateToEmpty
public void VerifyNewLinesAndTabsEvaluateToEmpty()
{
MockLogger mockLogger = new MockLogger();
string projectFileContent = ObjectModelHelpers.CleanupFileContents(@"
<Project xmlns='msbuildnamespace'>
<PropertyGroup><NewLine>" + Environment.NewLine + Environment.NewLine + "</NewLine></PropertyGroup>" +
"<PropertyGroup><Tab>\t\t\t\t</Tab></PropertyGroup>" +
"<PropertyGroup><CarriageReturn>\r\r\r\r</CarriageReturn></PropertyGroup>" +
@"<PropertyGroup><Message1 Condition =""'$(NewLine)' == ''"">NewLineEvalAsEmpty</Message1></PropertyGroup>
<PropertyGroup><Message2 Condition =""'$(Tab)' == ''"">TabEvalAsEmpty</Message2></PropertyGroup>
<PropertyGroup><Message3 Condition =""'$(CarriageReturn)' == ''"">CarriageReturnEvalAsEmpty</Message3></PropertyGroup>
<Target Name=""BUild"">
<Message Text=""$(Message1)"" Importance=""High""/>
<Message Text=""$(Message2)"" Importance=""High""/>
<Message Text=""$(Message3)"" Importance=""High""/>
</Target>
</Project>");
ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(projectFileContent)));
Project project = new Project(xml);
bool result = project.Build(new ILogger[] { mockLogger });
Assert.Equal(true, result);
mockLogger.AssertLogContains("NewLineEvalAsEmpty");
mockLogger.AssertLogContains("TabEvalAsEmpty");
mockLogger.AssertLogContains("CarriageReturnEvalAsEmpty");
}
示例3: Compile
public static bool Compile(Project project, string logfile, Log log)
{
try
{
if (project != null)
{
var doLog = false;
var logErrorFile = Path.Combine(Directories.LogsDir, ("Error - " + Path.GetFileName(logfile)));
if (File.Exists(logErrorFile))
{
File.Delete(logErrorFile);
}
if (!string.IsNullOrWhiteSpace(logfile))
{
var logDir = Path.GetDirectoryName(logfile);
if (!string.IsNullOrWhiteSpace(logDir))
{
doLog = true;
if (!Directory.Exists(logDir))
{
Directory.CreateDirectory(logDir);
}
var fileLogger = new FileLogger { Parameters = @"logfile=" + logfile, ShowSummary = true };
ProjectCollection.GlobalProjectCollection.RegisterLogger(fileLogger);
}
}
var result = project.Build();
ProjectCollection.GlobalProjectCollection.UnregisterAllLoggers();
ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
Utility.Log(
result ? LogStatus.Ok : LogStatus.Error, "Compiler",
result
? string.Format("Compile - {0}", project.FullPath)
: string.Format("Compile - Check ./logs/ for details - {0}", project.FullPath), log);
if (!result && doLog && File.Exists(logfile))
{
var pathDir = Path.GetDirectoryName(logfile);
if (!string.IsNullOrWhiteSpace(pathDir))
{
File.Move(
logfile, Path.Combine(Directories.LogsDir, ("Error - " + Path.GetFileName(logfile))));
}
}
else if (result && File.Exists(logfile))
{
File.Delete(logfile);
}
return result;
}
}
catch (Exception ex)
{
Utility.Log(LogStatus.Error, "Compiler", ex.Message, log);
}
return false;
}
示例4: DoRun
protected override void DoRun()
{
Environment.CurrentDirectory = _fileInfo.DirectoryName;
List<string> targets = _targets.ConvertAll(prop => prop.Name);
_project = _projects.LoadProject(_fileInfo.FullName);
_project.Build(targets.ToArray(), _loggers);
//SetTargetFramework();
}
示例5: CompileLibMooNet
private static bool CompileLibMooNet(string libmoonetPath)
{
Console.WriteLine("Compiling LibMoonet...");
if (File.Exists(Program.madcowINI))
{
IConfigSource source = new IniConfigSource(Program.madcowINI);
String Src = source.Configs["Balloons"].Get("ShowBalloons");
if (Src.Contains("1")) { Form1.GlobalAccess.MadCowTrayIcon.ShowBalloonTip(1000, "MadCow", "Compiling LibMoonet...", ToolTipIcon.Info); }
}
var libmoonetProject = new Project(libmoonetPath);
return libmoonetProject.Build(new Microsoft.Build.Logging.FileLogger());
}
示例6: Main
static void Main(string[] args)
{
//SolutionFile solutionFile = SolutionFile.Parse();
//Microsoft.Build.Evaluation.Project project = new Microsoft.Build.Evaluation.Project();
//SolutionParser parser = new SolutionParser();
//parser.SolutionFile = @"D:\Projects\WFAppsHelper\TestProjectSolution\TestProjectSolution.sln";
//parser.ParseSolutionFile();
ProjectRootElement rootElement = ProjectRootElement.Open(@"D:\Projects\WFAppsHelper\TestProjectSolution\TestProjectSolution\TestProjectSolution.csproj");
Project project = new Project(rootElement);
project.ProjectCollection.RegisterLogger(new ConsoleLogger());
project.ProjectCollection.SetGlobalProperty("EnableNuGetPackageRestore", "true");
project.Build();
Console.Read();
}
示例7: BuildProject
public void BuildProject(string projectName)
{
var globalProperties = new Dictionary<string, string>(){
{"Configuration", "Debug"},
{"SolutionDir", SolutionDir},
{"OutputPath", OutputPath},
//{"VSToolsPath", @"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0"}
//{"VSToolsPath", @"c:\program files (x86)MSBuild\Microsoft\Microsoft\VisualStudio\v12.0"}
};
var project = new Project(Path.Combine(TestProjectsDir, projectName, projectName + ".csproj"),
globalProperties, "12.0");
var logger = new ConsoleLogger(LoggerVerbosity.Diagnostic);
Assert.IsTrue(project.Build(logger));
ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
}
示例8: BuildSolutions
public void BuildSolutions(List<string> solutionFiles)
{
foreach (string solution in solutionFiles)
{
buildLog.AppendLine("Preparing to build " + solution);
Project project = new Project(solution);
try
{
project.Build();
buildLog.AppendLine("Solution built.");
}
catch (Exception e)
{
buildLog.AppendLine(e.Message);
}
ProjectCollection.GlobalProjectCollection.UnloadProject(project);
}
}
示例9: CompileClassifier
/// <summary>
/// Creates a DecisionTreeClassifier.exe from a decision tree, returning the file path of the new exe
/// </summary>
public static string CompileClassifier(TreeNode decisionTree)
{
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var assemblyDirectory = new FileInfo(assemblyLocation).DirectoryName ?? "";
var classifierDir = Path.Combine(assemblyDirectory, "DecisionTreeClassifier");
var projFullPath = Path.Combine(classifierDir, "DecisionTreeClassifier.csproj");
var mainFullPath = Path.Combine(classifierDir, "Program.cs");
ReplaceSerializedTreeLine(mainFullPath, decisionTree);
// load up the classifier project
var proj = new Project(projFullPath);
// set project to compile special DecisionTree config
proj.SetProperty("Configuration", "DecisionTree");
// set the output path
proj.SetProperty("DecisionTreeOutputPath", assemblyDirectory);
// make a logger to catch possible build errors
var logger = new SimpleBuildLogger();
// if we failed to build the classifier, we're screwed
if (!proj.Build(logger))
{
var sb = new StringBuilder();
sb.AppendLine("***************************************");
sb.AppendLine("**** Failed To Compile Classifier! ****");
sb.AppendLine("***************************************");
foreach (var error in logger.Errors)
{
sb.AppendLine(error.Message + " " + error.File + ": " + error.LineNumber);
}
throw new Exception(sb.ToString());
}
// return the executable name
var exeFileName = proj.GetProperty("AssemblyName").EvaluatedValue + ".exe";
return Path.Combine(assemblyDirectory, exeFileName);
}
示例10: Basic
public void Basic()
{
MockLogger l = new MockLogger();
Project p = new Project(XmlReader.Create(new StringReader(ObjectModelHelpers.CleanupFileContents(@"
<Project DefaultTargets='Build' ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<Target Name='CleanUp'>
<Message Text='CleanUp-was-called.'/>
</Target>
<Target Name='Build'>
<Error Text='This is an error.'/>
<OnError ExecuteTargets='CleanUp'/>
</Target>
</Project>"))));
p.Build(new string[] { "Build" }, new ILogger[] { l });
Assert.Equal(1, l.ErrorCount); // "Expected one error because 'Build' failed."
Assert.True((l.FullLog.IndexOf("CleanUp-was-called") != -1)); // "The CleanUp target should have been called."
}
示例11: EmptyItemSpecInTargetInputs
public void EmptyItemSpecInTargetInputs()
{
MockLogger ml = new MockLogger();
Project p = new Project(XmlReader.Create(new StringReader(ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<ItemGroup>
<MyFile Include='a.cs; b.cs; c.cs'/>
</ItemGroup>
<Target Name='Build'
Inputs=""@(MyFile->'%(NonExistentMetadata)')""
Outputs='foo.exe'>
<Message Text='Running Build target' Importance='High'/>
</Target>
</Project>"))));
bool success = p.Build(new string[] { "Build" }, new ILogger[] { ml });
Assert.True(success);
// It should have actually skipped the "Build" target since there were no inputs.
ml.AssertLogDoesntContain("Running Build target");
}
示例12: MSBuildLastTaskResult
public void MSBuildLastTaskResult()
{
string projectFileContents = ObjectModelHelpers.CleanupFileContents(@"
<Project DefaultTargets='t2' ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<Target Name='t'>
<Message Text='[start:$(MSBuildLastTaskResult)]'/> <!-- Should be blank -->
<Warning Text='warning'/>
<Message Text='[0:$(MSBuildLastTaskResult)]'/> <!-- Should be true, only a warning-->
<!-- task's Execute returns false -->
<Copy SourceFiles='|' DestinationFolder='c:\' ContinueOnError='true' />
<PropertyGroup>
<p>$(MSBuildLastTaskResult)</p>
</PropertyGroup>
<Message Text='[1:$(MSBuildLastTaskResult)]'/> <!-- Should be false: propertygroup did not reset it -->
<Message Text='[p:$(p)]'/> <!-- Should be false as stored earlier -->
<Message Text='[2:$(MSBuildLastTaskResult)]'/> <!-- Message succeeded, should now be true -->
</Target>
<Target Name='t2' DependsOnTargets='t'>
<Message Text='[3:$(MSBuildLastTaskResult)]'/> <!-- Should still have true -->
<!-- check Error task as well -->
<Error Text='error' ContinueOnError='true' />
<Message Text='[4:$(MSBuildLastTaskResult)]'/> <!-- Should be false -->
<!-- trigger OnError target, ContinueOnError is false -->
<Error Text='error2'/>
<OnError ExecuteTargets='t3'/>
</Target>
<Target Name='t3' >
<Message Text='[5:$(MSBuildLastTaskResult)]'/> <!-- Should be false -->
</Target>
</Project>");
Project project = new Project(XmlReader.Create(new StringReader(projectFileContents)));
List<ILogger> loggers = new List<ILogger>();
MockLogger logger = new MockLogger();
loggers.Add(logger);
project.Build("t2", loggers);
logger.AssertLogContains("[start:]");
logger.AssertLogContains("[0:true]");
logger.AssertLogContains("[1:false]");
logger.AssertLogContains("[p:false]");
logger.AssertLogContains("[2:true]");
logger.AssertLogContains("[3:true]");
logger.AssertLogContains("[4:false]");
logger.AssertLogContains("[4:false]");
}
示例13: TaskOutputBatching
public void TaskOutputBatching()
{
MockLogger logger = new MockLogger();
string projectFileContents = ObjectModelHelpers.CleanupFileContents(@"
<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<ItemGroup>
<TaskParameterItem Include=""foo"">
<ParameterName>Value</ParameterName>
<ParameterName2>Include</ParameterName2>
<PropertyName>MetadataProperty</PropertyName>
<ItemType>MetadataItem</ItemType>
</TaskParameterItem>
</ItemGroup>
<Target Name='Build'>
<CreateProperty Value=""@(TaskParameterItem)"">
<Output TaskParameter=""Value"" PropertyName=""Property1""/>
</CreateProperty>
<Message Text='Property1=[$(Property1)]' />
<CreateProperty Value=""@(TaskParameterItem)"">
<Output TaskParameter=""%(TaskParameterItem.ParameterName)"" PropertyName=""Property2""/>
</CreateProperty>
<Message Text='Property2=[$(Property2)]' />
<CreateProperty Value=""@(TaskParameterItem)"">
<Output TaskParameter=""Value"" PropertyName=""%(TaskParameterItem.PropertyName)""/>
</CreateProperty>
<Message Text='MetadataProperty=[$(MetadataProperty)]' />
<CreateItem Include=""@(TaskParameterItem)"">
<Output TaskParameter=""Include"" ItemName=""TestItem1""/>
</CreateItem>
<Message Text='TestItem1=[@(TestItem1)]' />
<CreateItem Include=""@(TaskParameterItem)"">
<Output TaskParameter=""%(TaskParameterItem.ParameterName2)"" ItemName=""TestItem2""/>
</CreateItem>
<Message Text='TestItem2=[@(TestItem2)]' />
<CreateItem Include=""@(TaskParameterItem)"">
<Output TaskParameter=""Include"" ItemName=""%(TaskParameterItem.ItemType)""/>
</CreateItem>
<Message Text='MetadataItem=[@(MetadataItem)]' />
</Target>
</Project>");
Project project = new Project(XmlReader.Create(new StringReader(projectFileContents)));
List<ILogger> loggers = new List<ILogger>();
loggers.Add(logger);
project.Build(loggers);
logger.AssertLogContains("Property1=[foo]");
logger.AssertLogContains("Property2=[foo]");
logger.AssertLogContains("MetadataProperty=[foo]");
logger.AssertLogContains("TestItem1=[foo]");
logger.AssertLogContains("TestItem2=[foo]");
logger.AssertLogContains("MetadataItem=[foo]");
}
示例14: OverridePropertiesInInferredCreateProperty
public void OverridePropertiesInInferredCreateProperty()
{
string[] files = null;
try
{
files = ObjectModelHelpers.GetTempFiles(2, new DateTime(2005, 1, 1));
MockLogger logger = new MockLogger();
string projectFileContents = ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<ItemGroup>
<i Include='" + files[0] + "'><output>" + files[1] + @"</output></i>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include='a.resx'>
<LogicalName>foo</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include='b.resx'>
<LogicalName>bar</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include='c.resx'>
<LogicalName>barz</LogicalName>
</EmbeddedResource>
</ItemGroup>
<Target Name='t2' DependsOnTargets='t'>
<Message Text='final:[$(LinkSwitches)]'/>
</Target>
<Target Name='t' Inputs='%(i.Identity)' Outputs='%(i.Output)'>
<Message Text='start:[Hello]'/>
<CreateProperty Value=""@(EmbeddedResource->'/assemblyresource:%(Identity),%(LogicalName)', ' ')""
Condition=""'%(LogicalName)' != '' "">
<Output TaskParameter=""Value"" PropertyName=""LinkSwitches""/>
</CreateProperty>
<Message Text='end:[hello]'/>
</Target>
</Project>");
Project project = new Project(XmlReader.Create(new StringReader(projectFileContents)));
List<ILogger> loggers = new List<ILogger>();
loggers.Add(logger);
project.Build("t2", loggers);
// We should only see messages from the second target, as the first is only inferred
logger.AssertLogDoesntContain("start:");
logger.AssertLogDoesntContain("end:");
logger.AssertLogContains(new string[] { "final:[/assemblyresource:c.resx,barz]" });
logger.AssertLogDoesntContain(ResourceUtilities.FormatResourceString("TaskStarted", "CreateProperty"));
logger.AssertLogContains(new string[] { ResourceUtilities.FormatResourceString("PropertyOutputOverridden", "LinkSwitches", "/assemblyresource:a.resx,foo", "/assemblyresource:b.resx,bar") });
logger.AssertLogContains(new string[] { ResourceUtilities.FormatResourceString("PropertyOutputOverridden", "LinkSwitches", "/assemblyresource:b.resx,bar", "/assemblyresource:c.resx,barz") });
}
finally
{
ObjectModelHelpers.DeleteTempFiles(files);
}
}
示例15: OverridePropertiesInCreateProperty
public void OverridePropertiesInCreateProperty()
{
MockLogger logger = new MockLogger();
string projectFileContents = ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='msbuildnamespace'>
<ItemGroup>
<EmbeddedResource Include='a.resx'>
<LogicalName>foo</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include='b.resx'>
<LogicalName>bar</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include='c.resx'>
<LogicalName>barz</LogicalName>
</EmbeddedResource>
</ItemGroup>
<Target Name='t'>
<CreateProperty Value=""@(EmbeddedResource->'/assemblyresource:%(Identity),%(LogicalName)', ' ')""
Condition=""'%(LogicalName)' != '' "">
<Output TaskParameter=""Value"" PropertyName=""LinkSwitches""/>
</CreateProperty>
<Message Text='final:[$(LinkSwitches)]'/>
</Target>
</Project>");
Project project = new Project(XmlReader.Create(new StringReader(projectFileContents)));
List<ILogger> loggers = new List<ILogger>();
loggers.Add(logger);
project.Build("t", loggers);
logger.AssertLogContains(new string[] { "final:[/assemblyresource:c.resx,barz]" });
logger.AssertLogContains(new string[] { ResourceUtilities.FormatResourceString("TaskStarted", "CreateProperty") });
logger.AssertLogContains(new string[] { ResourceUtilities.FormatResourceString("PropertyOutputOverridden", "LinkSwitches", "/assemblyresource:a.resx,foo", "/assemblyresource:b.resx,bar") });
logger.AssertLogContains(new string[] { ResourceUtilities.FormatResourceString("PropertyOutputOverridden", "LinkSwitches", "/assemblyresource:b.resx,bar", "/assemblyresource:c.resx,barz") });
}