public static BuildResult BuildProject(string projectPath, string configuration, string[] targets, Dictionary <string, string> properties, string toolsVersion) { if (!File.Exists(projectPath)) { throw new ArgumentException("Project path " + projectPath + " did not exist."); } if (string.IsNullOrEmpty(toolsVersion)) { toolsVersion = "4.0"; } if (properties == null) { properties = new Dictionary <string, string>(); } if (!properties.ContainsKey("Configuration") && !string.IsNullOrWhiteSpace(configuration)) { properties.Add("Configuration", configuration); } if (targets == null) { var doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(projectPath)); XmlNode defaultTargets = doc.SelectSingleNode("/Project[@DefaultTargets]"); if (defaultTargets != null) { targets = defaultTargets.Value.Split(';'); } } var logger = new MsBuildCollectionLogger(); var buildRequest = new BuildRequestData(projectPath, properties, toolsVersion, targets, null); var projects = new ProjectCollection(); projects.RegisterLogger(logger); var parameters = new BuildParameters(projects); parameters.Loggers = projects.Loggers; Debug.Assert(targets != null, "dsfsdsf"); logger.AddMessage(new Message(string.Format("Building {0} ({1}), {2} targets using {3} tools", projectPath, configuration, string.Join(", ", targets), toolsVersion), MessageType.Info)); var result = BuildManager.DefaultBuildManager.Build(parameters, buildRequest); return(new BuildResult(logger.Messages, result.OverallResult == BuildResultCode.Success)); }
public static BuildResult BuildProject(string projectPath, string configuration, string[] targets, Dictionary<string, string> properties, string toolsVersion) { if (!File.Exists(projectPath)) { throw new ArgumentException("Project path " + projectPath + " did not exist."); } if (string.IsNullOrEmpty(toolsVersion)) toolsVersion = "4.0"; if (properties == null) properties = new Dictionary<string, string>(); if (!properties.ContainsKey("Configuration") && !string.IsNullOrWhiteSpace(configuration)) properties.Add("Configuration", configuration); if (targets == null) { var doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(projectPath)); XmlNode defaultTargets = doc.SelectSingleNode("/Project[@DefaultTargets]"); if (defaultTargets != null) targets = defaultTargets.Value.Split(';'); } var logger = new MsBuildCollectionLogger(); var buildRequest = new BuildRequestData(projectPath, properties, toolsVersion, targets, null); var projects = new ProjectCollection(); projects.RegisterLogger(logger); var parameters = new BuildParameters(projects); parameters.Loggers = projects.Loggers; Debug.Assert(targets != null, "dsfsdsf"); logger.AddMessage(new Message(string.Format("Building {0} ({1}), {2} targets using {3} tools", projectPath, configuration, string.Join(", ", targets), toolsVersion), MessageType.Info)); var result = BuildManager.DefaultBuildManager.Build(parameters, buildRequest); return new BuildResult(logger.Messages, result.OverallResult == BuildResultCode.Success); }