Guest User

Untitled

a guest
Feb 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. public bool Build()
  2. {
  3. Dictionary<string, string> globalProperty = new Dictionary<string, string>
  4. {
  5. { "Configuration", "Debug" },
  6. { "Platform", "Any CPU" },
  7. { "VisualStudioVersion", "14.0"}
  8. };
  9.  
  10. string pathToLog = ConfigHelper.CheckConfig("ServiceBuildLogPath");
  11.  
  12. ProjectCollection pc = new ProjectCollection();
  13. BuildParameters bp = new BuildParameters(pc)
  14. {
  15. Loggers = new List<Microsoft.Build.Framework.ILogger>() { new Microsoft.Build.BuildEngine.FileLogger() { Parameters = "logfile=" + pathToLog + @"MSBuild.log" } },
  16. DefaultToolsVersion = "14.0"
  17. };
  18.  
  19. BuildResult buildResult = null;
  20.  
  21. BuildRequestData buildRequest;
  22.  
  23. foreach (Solution solution in _services)
  24. {
  25. try
  26. {
  27. if (File.Exists(solution.PathToSolution))
  28. {
  29. if (_nugetPackageRestore.Restore(solution.PathToSolution))
  30. {
  31. buildRequest = new BuildRequestData(solution.PathToSolution, globalProperty, "4.0", new string[] { "Build" }, null);
  32. buildResult = Microsoft.Build.Execution.BuildManager.DefaultBuildManager.Build(bp, buildRequest);
  33.  
  34. if (buildResult.OverallResult != BuildResultCode.Success)
  35. {
  36. if (buildResult.Exception != null)
  37. {
  38. throw buildResult.Exception;
  39. }
  40.  
  41. throw new Exception(string.Format("Unable to build solution {0}", solution.Name));
  42. }
  43. }
  44. }
  45. else
  46. {
  47. throw new FileNotFoundException(string.Format("Solution {0} is unavailable", solution.Name));
  48. }
  49. }
  50. catch
  51. {
  52. throw;
  53. }
  54. }
  55.  
  56. return buildResult != null && buildResult.OverallResult == BuildResultCode.Success;
  57. }
Add Comment
Please, Sign In to add comment