protected async Task <BuildInfo> BuildAsync(string taskName, MSB.Framework.ITaskHost taskHost, CancellationToken cancellationToken) { // create a project instance to be executed by build engine. // The executed project will hold the final model of the project after execution via msbuild. var executedProject = _loadedProject.CreateProjectInstance(); if (!executedProject.Targets.ContainsKey("Compile")) { return(new BuildInfo(executedProject, null)); } var hostServices = new Microsoft.Build.Execution.HostServices(); // connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task. hostServices.RegisterHostObject(_loadedProject.FullPath, "CoreCompile", taskName, taskHost); var buildParameters = new MSB.Execution.BuildParameters(_loadedProject.ProjectCollection); var buildRequestData = new MSB.Execution.BuildRequestData(executedProject, new string[] { "Compile" }, hostServices); BuildResult result = await this.BuildAsync(buildParameters, buildRequestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); if (result.OverallResult == BuildResultCode.Failure) { return(new BuildInfo(executedProject, result.Exception?.Message ?? "")); } else { return(new BuildInfo(executedProject, null)); } }
protected async Task <BuildResult> BuildAsync(string taskName, MSB.Framework.ITaskHost taskHost, CancellationToken cancellationToken) { // prepare for building var buildTargets = new BuildTargets(loadedProject, "Compile"); // Don't execute this one. It will build referenced projects. // Even when DesignTimeBuild is defined above, it will still add the referenced project's output to the references list // which we don't want. buildTargets.Remove("ResolveProjectReferences"); // don't execute anything after CoreCompile target, since we've // already done everything we need to compute compiler inputs by then. buildTargets.RemoveAfter("CoreCompile", includeTargetInRemoval: false); // create a project instance to be executed by build engine. // The executed project will hold the final model of the project after execution via msbuild. var executedProject = loadedProject.CreateProjectInstance(); var hostServices = new Microsoft.Build.Execution.HostServices(); // connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task. hostServices.RegisterHostObject(this.loadedProject.FullPath, "CoreCompile", taskName, taskHost); var buildParameters = new MSB.Execution.BuildParameters(loadedProject.ProjectCollection); var buildRequestData = new MSB.Execution.BuildRequestData(executedProject, buildTargets.Targets, hostServices); var result = await this.BuildAsync(buildParameters, buildRequestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); return(new BuildResult(result, executedProject)); }
protected async Task <BuildInfo> BuildAsync(string taskName, MSB.Framework.ITaskHost taskHost, CancellationToken cancellationToken) { // create a project instance to be executed by build engine. // The executed project will hold the final model of the project after execution via msbuild. var executedProject = _loadedProject.CreateProjectInstance(); if (!executedProject.Targets.ContainsKey("Compile")) { return(new BuildInfo(executedProject, null)); } var hostServices = new MSB.Execution.HostServices(); // connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task. hostServices.RegisterHostObject(_loadedProject.FullPath, "CoreCompile", taskName, taskHost); var buildParameters = new MSB.Execution.BuildParameters(_loadedProject.ProjectCollection); // capture errors that are output in the build log var errorBuilder = new StringWriter(); var errorLogger = new ErrorLogger(errorBuilder) { Verbosity = MSB.Framework.LoggerVerbosity.Normal }; buildParameters.Loggers = new MSB.Framework.ILogger[] { errorLogger }; var buildRequestData = new MSB.Execution.BuildRequestData(executedProject, new string[] { "Compile" }, hostServices); var result = await this.BuildAsync(buildParameters, buildRequestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); if (result.OverallResult == MSB.Execution.BuildResultCode.Failure) { if (result.Exception != null) { return(new BuildInfo(executedProject, result.Exception.Message)); } else { return(new BuildInfo(executedProject, errorBuilder.ToString())); } } else { return(new BuildInfo(executedProject, null)); } }
protected async Task <ProjectInstance> BuildAsync(string taskName, MSB.Framework.ITaskHost taskHost, CancellationToken cancellationToken) { // prepare for building var buildTargets = new BuildTargets(_loadedProject, "Compile"); // don't execute anything after CoreCompile target, since we've // already done everything we need to compute compiler inputs by then. buildTargets.RemoveAfter("CoreCompile", includeTargetInRemoval: false); // create a project instance to be executed by build engine. // The executed project will hold the final model of the project after execution via msbuild. var executedProject = _loadedProject.CreateProjectInstance(); if (!executedProject.Targets.ContainsKey("Compile")) { return(executedProject); } var hostServices = new Microsoft.Build.Execution.HostServices(); // connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task. hostServices.RegisterHostObject(_loadedProject.FullPath, "CoreCompile", taskName, taskHost); var buildParameters = new MSB.Execution.BuildParameters(_loadedProject.ProjectCollection); var buildRequestData = new MSB.Execution.BuildRequestData(executedProject, buildTargets.Targets, hostServices); var result = await this.BuildAsync(buildParameters, buildRequestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); if (result.Exception != null) { throw result.Exception; } return(executedProject); }