private void Build(string[] targets, BuildOutput buildOutput, out bool result, out IDictionary <string, TargetResult> targetOutputs) { lock (BuildManager.DefaultBuildManager) { BuildRequestData restoreRequest = new BuildRequestData( ProjectInstance, targetsToBuild: targets ?? ProjectInstance.DefaultTargets.ToArray(), hostServices: null, flags: BuildRequestDataFlags.ReplaceExistingProjectInstance); BuildParameters buildParameters = new BuildParameters { Loggers = new List <Framework.ILogger>(ProjectCollection.Loggers.Concat(buildOutput.AsEnumerable())), }; BuildManager.DefaultBuildManager.BeginBuild(buildParameters); try { BuildSubmission buildSubmission = BuildManager.DefaultBuildManager.PendBuildRequest(restoreRequest); BuildResult buildResult = buildSubmission.Execute(); result = buildResult.OverallResult == BuildResultCode.Success; targetOutputs = buildResult.ResultsByTarget; } finally { BuildManager.DefaultBuildManager.EndBuild(); } } }
private void Restore(IDictionary <string, string>?globalProperties, BuildOutput buildOutput, out bool result, out IDictionary <string, TargetResult> targetOutputs) { Save(); // IMPORTANT: Make a copy of the global properties here so as not to modify the ones passed in Dictionary <string, string> restoreGlobalProperties = new Dictionary <string, string>(globalProperties ?? ProjectCollection.GlobalProperties); restoreGlobalProperties["ExcludeRestorePackageImports"] = "true"; restoreGlobalProperties["MSBuildRestoreSessionId"] = Guid.NewGuid().ToString("D"); BuildResult buildResult = BuildManagerHost.Build( FullPath, new[] { "Restore" }, restoreGlobalProperties, new List <Framework.ILogger>(ProjectCollection.Loggers.Concat(buildOutput.AsEnumerable())), BuildRequestDataFlags.ClearCachesAfterBuild | BuildRequestDataFlags.SkipNonexistentTargets | BuildRequestDataFlags.IgnoreMissingEmptyAndInvalidImports); targetOutputs = buildResult.ResultsByTarget; if (buildResult.Exception != null) { throw buildResult.Exception; } result = buildResult.OverallResult == BuildResultCode.Success; }
/// <summary> /// Attempts to run the Restore target for the current project with a unique evaluation context. /// </summary> /// <param name="globalProperties">Global properties to use when running the Restore the target.</param> /// <param name="result">A value indicating the result of the restore.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the restore.</param> /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryRestore(IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult>?targetOutputs) { buildOutput = BuildOutput.Create(); Restore(globalProperties, buildOutput, out result, out targetOutputs); return(this); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="restore">A value indicating whether or not the project should be restored before building.</param> /// <param name="globalProperties">Global properties to use when building the target.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the build.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryBuild(bool restore, IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput) { buildOutput = BuildOutput.Create(); Build(restore, null, globalProperties, buildOutput, out result, out _); return(this); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="restore">A value indicating whether or not the project should be restored before building.</param> /// <param name="target">The name of the target to build.</param> /// <param name="globalProperties">Global properties to use when building the target.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the build.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryBuild(bool restore, string target, IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput) { buildOutput = BuildOutput.Create(); Build(restore, target.ToArrayWithSingleElement(), globalProperties, buildOutput, out result, out _); return(this); }
/// <summary> /// Attempts to run the Restore target for the current project with a unique evaluation context. /// </summary> /// <param name="result">A value indicating the result of the restore.</param> /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the restore.</param> /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryRestore(out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs) { Save(); buildOutput = BuildOutput.Create(); lock (BuildManager.DefaultBuildManager) { BuildRequestData restoreRequest = new BuildRequestData( FullPath, new Dictionary <string, string> { ["ExcludeRestorePackageImports"] = "true", ["MSBuildRestoreSessionId"] = Guid.NewGuid().ToString("D"), }, ProjectCollection.DefaultToolsVersion, targetsToBuild: new[] { "Restore" }, hostServices: null, flags: BuildRequestDataFlags.ClearCachesAfterBuild | BuildRequestDataFlags.SkipNonexistentTargets | BuildRequestDataFlags.IgnoreMissingEmptyAndInvalidImports); BuildParameters buildParameters = new BuildParameters { Loggers = new List <Framework.ILogger> { buildOutput, }, }; BuildManager.DefaultBuildManager.BeginBuild(buildParameters); try { BuildSubmission buildSubmission = BuildManager.DefaultBuildManager.PendBuildRequest(restoreRequest); BuildResult buildResult = buildSubmission.Execute(); result = buildResult.OverallResult == BuildResultCode.Success; targetOutputs = buildResult.ResultsByTarget; } finally { BuildManager.DefaultBuildManager.EndBuild(); } } Project.MarkDirty(); Project.ReevaluateIfNecessary(); return(this); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="restore">A value indicating whether or not the project should be restored before building.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryBuild(bool restore, out bool result, out BuildOutput buildOutput) { if (restore) { TryRestore(out result, out buildOutput); if (!result) { return(this); } } else { buildOutput = BuildOutput.Create(); } Build(null, buildOutput, out result, out _); return(this); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="restore">A value indicating whether or not the project should be restored before building.</param> /// <param name="targets">The names of the targets to build.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param> /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryBuild(bool restore, string[] targets, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs) { if (restore) { TryRestore(out result, out buildOutput, out targetOutputs); if (!result) { return(this); } } else { buildOutput = BuildOutput.Create(); } Build(targets, buildOutput, out result, out targetOutputs); return(this); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="restore">A value indicating whether or not the project should be restored before building.</param> /// <param name="target">The name of the target to build.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryBuild(bool restore, string target, out bool result, out BuildOutput buildOutput) { if (restore) { TryRestore(out result, out buildOutput); if (!result) { return(this); } } else { buildOutput = BuildOutput.Create(); } Build(target.ToArrayWithSingleElement(), buildOutput, out result, out _); return(this); }
/// <summary> /// Gets a <see cref="Project"/> instance from the current project. /// </summary> /// <param name="project">Receives the <see cref="Project"/> instance.</param> /// <param name="buildOutput">Receives <see cref="BuildOutput"/> instance.</param> /// <param name="globalProperties">Optional <see cref="IDictionary{String, String}"/> containing global properties.</param> /// <param name="toolsVersion">Optional tools version.</param> /// <param name="projectCollection">Optional <see cref="ProjectCollection"/> to use. Defaults to <code>ProjectCollection.GlobalProjectCollection</code>.</param> /// <param name="projectLoadSettings">Optional <see cref="ProjectLoadSettings"/> to use. Defaults to <see cref="ProjectLoadSettings.Default"/>.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryGetProject( out Project project, out BuildOutput buildOutput, IDictionary <string, string> globalProperties = null, string toolsVersion = null, ProjectCollection projectCollection = null, ProjectLoadSettings projectLoadSettings = ProjectLoadSettings.Default) { buildOutput = BuildOutput.Create(); projectCollection = projectCollection ?? new ProjectCollection(); projectCollection.RegisterLogger(buildOutput); project = new Project( RootElement, globalProperties, toolsVersion, projectCollection, projectLoadSettings); return(this); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="targets">The names of the targets to build.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the build.</param> /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryBuild(IEnumerable <string> targets, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult>?targetOutputs) { return(TryBuild(targets, null, out result, out buildOutput, out targetOutputs)); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="target">The name of the target to build.</param> /// <param name="globalProperties">Global properties to use when building the target.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the build.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryBuild(string target, IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput) { return(TryBuild(restore: false, target, globalProperties, out result, out buildOutput)); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="targets">The names of the targets to build.</param> /// <param name="globalProperties">Global properties to use when building the target.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the build.</param> /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryBuild(IEnumerable <string> targets, IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult>?targetOutputs) { return(TryBuild(restore: false, targets, globalProperties, out result, out buildOutput, out targetOutputs)); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="target">The name of the target to build.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryBuild(string target, out bool result, out BuildOutput buildOutput) { return(TryBuild(restore: false, target, out result, out buildOutput)); }
/// <summary> /// Attempts to run the Restore target for the current project with a unique evaluation context. /// </summary> /// <param name="result">A value indicating the result of the restore.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the restore.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryRestore(out bool result, out BuildOutput buildOutput) { return(TryRestore(null, out result, out buildOutput)); }
private void Build(string[] targets, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs) { buildOutput = BuildOutput.Create(); Build(targets, buildOutput, out result, out targetOutputs); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="restore">A value indicating whether or not the project should be restored before building.</param> /// <param name="targets">The names of the targets to build.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param> /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryBuild(bool restore, IEnumerable <string> targets, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs) { return(TryBuild(restore, targets.ToArray(), out result, out buildOutput, out targetOutputs)); }
/// <summary> /// Attempts to run the Restore target for the current project with a unique evaluation context. /// </summary> /// <param name="result">A value indicating the result of the restore.</param> /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the restore.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryRestore(out bool result, out BuildOutput buildOutput) { return(TryRestore(out result, out buildOutput, out IDictionary <string, TargetResult> _)); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="targets">The names of the targets to build.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param> /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryBuild(string[] targets, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs) { return(TryBuild(restore: false, targets, out result, out buildOutput, out targetOutputs)); }
/// <summary> /// Attempts to run the Restore target for the current project with a unique evaluation context. /// </summary> /// <param name="globalProperties">Global properties to use when running the Restore the target.</param> /// <param name="result">A value indicating the result of the restore.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the restore.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryRestore(IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput) { return(TryRestore(globalProperties, out result, out buildOutput, out IDictionary <string, TargetResult> _)); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="restore">A value indicating whether or not the project should be restored before building.</param> /// <param name="target">The name of the target to build.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param> /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> public ProjectCreator TryBuild(bool restore, string target, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs) { return(TryBuild(restore, new[] { target }, out result, out buildOutput, out targetOutputs)); }
private void Build(string[]?targets, IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult>?targetOutputs) { buildOutput = BuildOutput.Create(); Build(restore: false, targets, globalProperties, buildOutput, out result, out targetOutputs); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="restore">A value indicating whether or not the project should be restored before building.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the build.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryBuild(bool restore, out bool result, out BuildOutput buildOutput) { return(TryBuild(restore, globalProperties: null, out result, out buildOutput)); }
/// <summary> /// Attempts to build the current project. /// </summary> /// <param name="target">The name of the target to build.</param> /// <param name="result">A value indicating the result of the build.</param> /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the build.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TryBuild(string target, out bool result, out BuildOutput buildOutput) { return(TryBuild(target, null, out result, out buildOutput)); }
private void Build(bool restore, string[]?targets, IDictionary <string, string>?globalProperties, BuildOutput buildOutput, out bool result, out IDictionary <string, TargetResult>?targetOutputs) { targetOutputs = null; if (restore) { Restore(globalProperties, buildOutput, out result, out targetOutputs); if (!result) { return; } } ProjectInstance projectInstance; if (globalProperties != null) { TryGetProject(out Project project, globalProperties); projectInstance = project.CreateProjectInstance(); } else { projectInstance = ProjectInstance; } BuildResult buildResult = BuildManagerHost.Build( projectInstance, targets !, globalProperties !, new List <Framework.ILogger>(ProjectCollection.Loggers.Concat(buildOutput.AsEnumerable())), BuildRequestDataFlags.None); result = buildResult.OverallResult == BuildResultCode.Success; if (targetOutputs != null) { foreach (KeyValuePair <string, TargetResult> targetResult in buildResult.ResultsByTarget) { targetOutputs[targetResult.Key] = targetResult.Value; } } else { targetOutputs = buildResult.ResultsByTarget; } }