Building a .sln in C# executable

让人想犯罪 __ 提交于 2019-12-04 19:02:41

I managed to get it working, solution is not building to due errors in the code. Anyway this is the solution.

string projectFileName = Directory.GetCurrentDirectory() + "\\build\\Solution.sln";
ProjectCollection pc = new ProjectCollection();
Dictionary<string, string> GlobalProperty = new Dictionary<string, string>();
GlobalProperty.Add("Configuration", "Release");
GlobalProperty.Add("Platform", "Any CPU");
GlobalProperty.Add("OutputPath", Directory.GetCurrentDirectory() + "\\build\\\bin\\Release");

BuildParameters bp = new BuildParameters(pc);
bp.Loggers = new[] {
  new FileLogger
  {
    Verbosity = LoggerVerbosity.Detailed,
    ShowSummary = true,
    SkipProjectStartedText = true
  }
};

BuildManager.DefaultBuildManager.BeginBuild(bp);

BuildRequestData BuildRequest = new BuildRequestData(projectFileName, GlobalProperty, null, new string[] { "Build" }, null);

BuildSubmission BuildSubmission = BuildManager.DefaultBuildManager.PendBuildRequest(BuildRequest);
BuildSubmission.Execute();
BuildManager.DefaultBuildManager.EndBuild();
if (BuildSubmission.BuildResult.OverallResult == BuildResultCode.Failure)
  {
    throw new Exception();
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!