我尝试使用.NET 4.5中的新Microsoft.Build.Framework以编程方式构建包含C#项目的可视化工作室解决方案,但该解决方案无法成功构建。以下是我正在使用的代码:
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Microsoft.Build.Logging;
namespace ConsoleApplication1
{
class Program
{
public static void Main(string[] args)
{
string solutionPath = @"D:\Work\path_to_solution_file\MySolution.sln";
ProjectCollection pc = new ProjectCollection();
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
globalProperty.Add("OutputPath", @"C:\Users\Abhishek\Desktop\sample");
globalProperty.Add("Configuration", "Release");
globalProperty.Add("Platform", "Any CPU");
BuildParameters bpar = new BuildParameters(pc);
BuildRequestData BuildRequest = new BuildRequestData(solutionPath, globalProperty, null, new string[] { "Build" }, null);
BuildResult objresult = BuildManager.DefaultBuildManager.Build(bpar, BuildRequest);
if (objresult.OverallResult == BuildResultCode.Success)
Console.WriteLine("Success");
else
Console.WriteLine("Failure");
}
}
}
我搜索了几个论坛,但直到现在所提供的答案都没有。有人可以帮帮我吗?另外,如果我尝试将记录器附加到BuildParameters对象&#34; bpar&#34;,当我尝试调试代码时会出现以下异常:
System.MissingMethodException was unhandled
Message: An unhandled exception of type 'System.MissingMethodException' occurred in mscorlib.dll
Additional information: Method not found: 'Void Microsoft.Build.Execution.BuildParameters.set_Loggers(System.Collections.Generic.IEnumerable`1<Microsoft.Build.Framework.ILogger>)'.
为什么会这样?