本文整理汇总了C#中Microsoft.Build.Execution.BuildRequestData类的典型用法代码示例。如果您正苦于以下问题:C# BuildRequestData类的具体用法?C# BuildRequestData怎么用?C# BuildRequestData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BuildRequestData类属于Microsoft.Build.Execution命名空间,在下文中一共展示了BuildRequestData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
try
{
Console.WriteLine("LiteDevelop MSBuild");
var arguments = CommandLineArguments.Parse(args);
if (!File.Exists(arguments.InputFile))
throw new ArgumentException("File does not exist.");
var buildParameters = new BuildParameters();
buildParameters.DetailedSummary = arguments.DetailedSummary;
buildParameters.Loggers = new ILogger[]
{
new ConsoleLogger() { Verbosity = arguments.Verbosity }
};
Dictionary<string, string> properties = new Dictionary<string, string>();
var buildRequest = new BuildRequestData(arguments.InputFile, properties, null, new string[] { arguments.Target.ToString() }, null);
// Microsoft.Build.Execution.BuildManager.DefaultBuildManager.
var results = Microsoft.Build.Execution.BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);
}
catch (Exception ex)
{
Console.WriteLine("error: line=0 column=0 file=\"LiteDevelop.MSBuild.exe\" => " + ex.Message);
Console.WriteLine("This program should only be executed by LiteDevelop itself. If you believe this is a bug, please report the issue.");
}
}
示例2: Execute
public void Execute(WebsiteContext context)
{
Logger.Log("Building the solution...");
var solutionFilePath = Directory.GetFiles(context.CurrentDirectory).FirstOrDefault(x => x.EndsWith(".sln"));
var properties = new Dictionary<string, string> {
{"Configuration", "Debug"}
};
var buildParameters = new BuildParameters();
var buildLoggger = new InMemoryBuildLogger();
buildParameters.Loggers = new[] {buildLoggger};
var buildRequest = new BuildRequestData(solutionFilePath, properties, null, new[] { "Build" }, null);
var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);
if (buildResult.OverallResult == BuildResultCode.Failure) {
Logger.Error("Failed to build the solution!");
Logger.Space();
foreach (var buildError in buildLoggger.BuildErrors) {
Logger.Error(buildError);
}
Logger.Space();
}
else
Logger.Success("Solution successfully built.");
}
示例3: BuildAsync
internal static async Task<BuildResult> BuildAsync(this BuildManager buildManager, ITestOutputHelper logger, ProjectCollection projectCollection, ProjectRootElement project, string target, IDictionary<string, string> globalProperties = null, LoggerVerbosity logVerbosity = LoggerVerbosity.Detailed, ILogger[] additionalLoggers = null)
{
Requires.NotNull(buildManager, nameof(buildManager));
Requires.NotNull(projectCollection, nameof(projectCollection));
Requires.NotNull(project, nameof(project));
globalProperties = globalProperties ?? new Dictionary<string, string>();
var projectInstance = new ProjectInstance(project, globalProperties, null, projectCollection);
var brd = new BuildRequestData(projectInstance, new[] { target }, null, BuildRequestDataFlags.ProvideProjectStateAfterBuild);
var parameters = new BuildParameters(projectCollection);
var loggers = new List<ILogger>();
loggers.Add(new ConsoleLogger(logVerbosity, s => logger.WriteLine(s.TrimEnd('\r', '\n')), null, null));
loggers.AddRange(additionalLoggers);
parameters.Loggers = loggers.ToArray();
buildManager.BeginBuild(parameters);
var result = await buildManager.BuildAsync(brd);
buildManager.EndBuild();
return result;
}
示例4: Main
private static void Main()
{
try
{
// Run this in debug otherwise the files in CreateInstallers will be locked. :)
const string projectFileName = @"..\..\..\wix-custom-ba-issue.sln";
var pc = new ProjectCollection();
var globalProperty = new Dictionary<string, string> {{"Configuration", "Release"}};
var buildRequestData = new BuildRequestData(projectFileName, globalProperty, null, new[] {"Rebuild"},
null);
var buildParameters = new BuildParameters(pc)
{
DetailedSummary = true,
Loggers = new List<ILogger> {new ConsoleLogger()}
};
foreach (var version in new List<string> {"0.0.6.0", "1.0.0.0"})
BuildExamples(version, buildParameters, buildRequestData);
}
catch (Exception e)
{
Console.WriteLine("Failed!", e);
Console.WriteLine(e.ToString());
}
}
示例5: ExecuteAsync
/// <summary>
/// Builds a project.
/// </summary>
/// <param name="projectPath">The absolute path to the project.</param>
/// <param name="targetsToBuild">The targets to build. If not specified, the project's default target will be invoked.</param>
/// <param name="properties">The optional global properties to pass to the project. May come from the <see cref="MSBuild.Properties"/> static class.</param>
/// <returns>A task whose result is the result of the build.</returns>
public static async Task<BuildResultAndLogs> ExecuteAsync(string projectPath, string[] targetsToBuild = null, IDictionary<string, string> properties = null, ITestOutputHelper testLogger = null)
{
targetsToBuild = targetsToBuild ?? new string[0];
var logger = new EventLogger();
var logLines = new List<string>();
var parameters = new BuildParameters
{
Loggers = new List<ILogger>
{
new ConsoleLogger(LoggerVerbosity.Detailed, logLines.Add, null, null),
new ConsoleLogger(LoggerVerbosity.Minimal, v => testLogger?.WriteLine(v.TrimEnd()), null, null),
logger,
},
};
BuildResult result;
using (var buildManager = new BuildManager())
{
buildManager.BeginBuild(parameters);
try
{
var requestData = new BuildRequestData(projectPath, properties ?? Properties.Default, null, targetsToBuild, null);
var submission = buildManager.PendBuildRequest(requestData);
result = await submission.ExecuteAsync();
}
finally
{
buildManager.EndBuild();
}
}
return new BuildResultAndLogs(result, logger.LogEvents, logLines);
}
示例6: ReloadScripts
/// <summary>
///
/// </summary>
public static bool ReloadScripts()
{
if (SceneManager.GameProject == null) return false;
string projectFileName = SceneManager.GameProject.ProjectPath + @"\Scripts.csproj";
string tmpProjectFileName = SceneManager.GameProject.ProjectPath + @"\_Scripts.csproj";
string hash = string.Empty;
hash = GibboHelper.EncryptMD5(DateTime.Now.ToString());
try
{
/* Change the assembly Name */
XmlDocument doc = new XmlDocument();
doc.Load(projectFileName);
doc.GetElementsByTagName("Project").Item(0).ChildNodes[0]["AssemblyName"].InnerText = hash;
doc.Save(tmpProjectFileName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
/* Compile project */
ProjectCollection projectCollection = new ProjectCollection();
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>();
GlobalProperty.Add("Configuration", SceneManager.GameProject.Debug ? "Debug" : "Release");
GlobalProperty.Add("Platform", "x86");
BuildRequestData buildRequest = new BuildRequestData(tmpProjectFileName, GlobalProperty, null, new string[] { "Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(new BuildParameters(projectCollection), buildRequest);
Console.WriteLine(buildResult.OverallResult);
string cPath = SceneManager.GameProject.ProjectPath + @"\bin\" + (SceneManager.GameProject.Debug ? "Debug" : "Release") + "\\" + hash + ".dll";
if (File.Exists(cPath))
{
/* read assembly to memory without locking the file */
byte[] readAllBytes = File.ReadAllBytes(cPath);
SceneManager.ScriptsAssembly = Assembly.Load(readAllBytes);
if (SceneManager.ActiveScene != null)
{
SceneManager.ActiveScene.SaveComponentValues();
SceneManager.ActiveScene.Initialize();
}
Console.WriteLine("Path: " + SceneManager.ScriptsAssembly.GetName().Name);
}
else
{
File.Delete(tmpProjectFileName);
return false;
}
File.Delete(tmpProjectFileName);
return true;
}
示例7: BuildExamples
private static void BuildExamples(string versionString, BuildParameters buildParameters,
BuildRequestData buildRequestData)
{
const string versionFileName = @"..\..\..\.config\VersionInfo.txt";
File.WriteAllText(versionFileName, versionString);
var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequestData);
if (buildResult.OverallResult == BuildResultCode.Success)
{
var output =
buildResult.ResultsByTarget["Rebuild"].Items.First(x => x.ItemSpec.Contains("Bootstrapper"))
.ItemSpec;
var temp = Path.GetTempPath();
var productName = Path.GetFileNameWithoutExtension(output);
var fileName = Path.GetFileName(output);
if (productName != null)
{
var directory = Path.Combine(temp, productName, versionString);
if (Directory.Exists(directory))
Directory.Delete(directory, true);
Directory.CreateDirectory(directory);
if (fileName != null)
File.Copy(output, Path.Combine(directory, fileName));
}
}
}
示例8: process
/// <summary>
/// Process for specified event.
/// </summary>
/// <param name="evt">Configured event.</param>
/// <returns>Result of handling.</returns>
public override bool process(ISolutionEvent evt)
{
string command = ((IModeTargets)evt.Mode).Command;
ProjectRootElement root = getXml(parse(evt, command));
BuildRequestData request = new BuildRequestData(
new ProjectInstance(root, propertiesByDefault(evt), root.ToolsVersion, ProjectCollection.GlobalProjectCollection),
new string[] { ENTRY_POINT },
new HostServices()
);
// holy hedgehogs...
#if !NET_40
// Using of BuildManager from Microsoft.Build.dll, v4.0.0.0 - .NETFramework\v4.5\Microsoft.Build.dll
// you should see IDisposable, and of course you can see CA1001 for block as in #else section below.
using(BuildManager manager = new BuildManager(Settings.APP_NAME_SHORT)) {
return build(manager, request, evt.Process.Hidden);
}
#else
// Using of BuildManager from Microsoft.Build.dll, v4.0.30319 - .NETFramework\v4.0\Microsoft.Build.dll
// It doesn't implement IDisposable, and voila:
// https://ci.appveyor.com/project/3Fs/vssolutionbuildevent/build/build-103
return build(new BuildManager(Settings.APP_NAME_SHORT), request, evt.Process.Hidden);
#endif
}
示例9: Build
public BuildResult Build (BuildParameters parameters, BuildRequestData requestData)
{
BeginBuild (parameters);
var ret = BuildRequest (requestData);
EndBuild ();
return ret;
}
示例10: Start
public static string Start(DotnetBuildParams objBuildParams)
{
try
{
ProjectCollection pc = new ProjectCollection();
pc.DefaultToolsVersion = "4.0";
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>();
GlobalProperty.Add("Configuration", objBuildParams.Configuration);
GlobalProperty.Add("Platform", objBuildParams.Platform);
//Here, we set the property
GlobalProperty.Add("OutputPath", objBuildParams.OutputPath);
BuildRequestData BuidlRequest = new BuildRequestData(objBuildParams.projectFileName, GlobalProperty, null, objBuildParams.TargetsToBuild, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(new BuildParameters(pc), BuidlRequest);
return ((BuildResultCode)buildResult.OverallResult).ToString();
}
catch (Exception ex)
{
return BuildResultCode.Failure.ToString() ;
}
finally
{
}
}
示例11: Build
public static string[] Build(string solutionFile)
{
Console.Error.Write("// Building '{0}'... ", Path.GetFileName(solutionFile));
var pc = new ProjectCollection();
var parms = new BuildParameters(pc);
var globalProperties = new Dictionary<string, string>();
var request = new BuildRequestData(solutionFile, globalProperties, null, new string[] { "Build" }, null);
parms.Loggers = new[] {
new ConsoleLogger(LoggerVerbosity.Quiet)
};
var result = BuildManager.DefaultBuildManager.Build(parms, request);
var resultFiles = new HashSet<string>();
Console.Error.WriteLine("done.");
foreach (var kvp in result.ResultsByTarget) {
var targetResult = kvp.Value;
if (targetResult.Exception != null)
Console.Error.WriteLine("// Compilation failed for target '{0}':\r\n{1}", kvp.Key, targetResult.Exception.Message);
else {
foreach (var filename in targetResult.Items)
resultFiles.Add(filename.ItemSpec);
}
}
return resultFiles.ToArray();
}
示例12: Build
public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
{
lock (buildLock)
{
var projectFileName = Path.Combine(generateResult.DirectoryPath, ClassicGenerator.MainClassName + ".csproj");
var exeFilePath = Path.Combine(generateResult.DirectoryPath, ClassicGenerator.MainClassName + ".exe");
var consoleLogger = new MsBuildConsoleLogger(logger);
var globalProperties = new Dictionary<string, string>();
var buildRequest = new BuildRequestData(projectFileName, globalProperties, null, new[] { "Build" }, null);
var buildParameters = new BuildParameters(new ProjectCollection()) { DetailedSummary = false, Loggers = new Microsoft.Build.Framework.ILogger[] { consoleLogger } };
var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);
if (buildResult.OverallResult != BuildResultCode.Success && !File.Exists(exeFilePath))
{
logger.WriteLineInfo("BuildManager.DefaultBuildManager can't build this project. =(");
logger.WriteLineInfo("Let's try to build it via BuildBenchmark.bat!");
var buildProcess = new Process
{
StartInfo =
{
FileName = Path.Combine(generateResult.DirectoryPath, "BuildBenchmark.bat"),
WorkingDirectory = generateResult.DirectoryPath,
UseShellExecute = false,
RedirectStandardOutput = false,
}
};
buildProcess.Start();
buildProcess.WaitForExit();
if (File.Exists(exeFilePath))
return new BuildResult(generateResult, true, null, exeFilePath);
}
return new BuildResult(generateResult, buildResult.OverallResult == BuildResultCode.Success, buildResult.Exception, exeFilePath);
}
}
示例13: Build
public static BuildResult Build(string projectOrSolution, string targets, Dictionary<string, string> properties = null, ILogger logger = null)
{
if (!Path.IsPathRooted(projectOrSolution))
projectOrSolution = Path.Combine(ModuleInitializer.BaseDirectory, projectOrSolution);
if (!File.Exists(projectOrSolution))
throw new FileNotFoundException($"Project or solution to build {projectOrSolution} was not found.", projectOrSolution);
// Without this, builds end up running in process and colliding with each other,
// especially around the current directory used to resolve relative paths in projects.
Environment.SetEnvironmentVariable("MSBUILDNOINPROCNODE", "1");
using (var manager = new BuildManager(Guid.NewGuid().ToString()))
{
properties = properties ?? new Dictionary<string, string>();
// If file is not a solution, build up a fake solution configuration so P2P references just work
if (Path.GetExtension(projectOrSolution) != ".sln")
AddSolutionConfiguration(projectOrSolution, properties);
var request = new BuildRequestData(projectOrSolution, properties, "14.0", targets.Split(','), null);
var parameters = new BuildParameters
{
GlobalProperties = properties,
};
if (logger != null)
parameters.Loggers = new[] { logger };
return manager.Build(parameters, request);
}
}
示例14: Compile
bool Compile(params string[] targets)
{
using (var t = new ChangingOutput("Compiling target(s) {0} . . .", string.Join(", ", targets)))
{
t.FinishLine();
var logger = new ConsoleLogger(LoggerVerbosity.Quiet);
logger.SkipProjectStartedText = true;
var props = new Dictionary<string, string>
{
{"Configuration", _release ? "Release" : "Debug"},
};
var request = new BuildRequestData(_slnPath, props, null, targets, null);
var p = new BuildParameters()
{
Loggers = new[] {logger},
GlobalProperties = props
};
var result = BuildManager.DefaultBuildManager.Build(p, request);
t.PrintResult(result.OverallResult == BuildResultCode.Success);
return result.OverallResult == BuildResultCode.Success;
}
}
示例15: BuildSolution_VS
private bool BuildSolution_VS()
{
if (_SolutionPath == "") return false;
try
{
string projectFilePath = Path.Combine(_SolutionPath);
_OutputPath = _SolutionPath.Replace(Path.GetFileName(_SolutionPath), "") + "\\bin\\" + BuildInterface_Configuration.Text + "\\";
ProjectCollection pc = new ProjectCollection();
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
globalProperty.Add("OutputPath", _OutputPath);
BuildParameters bp = new BuildParameters(pc);
BuildRequestData buildRequest = new BuildRequestData(projectFilePath, globalProperty, "4.0", new string[] { "Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(bp, buildRequest);
if (buildResult.OverallResult == BuildResultCode.Success)
{
return true;
}
else
{
MessageBox.Show("There Are Errors", "Error");
}
}
catch
{
MessageBox.Show("Build Failed Unexpectedly", "Error");
}
return false;
}