private void BuildProject()
{
if (Build)
{
if (TargetFramework != null)
{
Logger.Log(MessageLevel.Info, NuGetResources.BuildingProjectTargetingFramework, TargetFramework);
}
using (var projectCollection = new ProjectCollection(ToolsetDefinitionLocations.Registry | ToolsetDefinitionLocations.ConfigurationFile))
{
BuildRequestData requestData = new BuildRequestData(_project.FullPath, Properties, _project.ToolsVersion, new string[0], null);
var parameters = new BuildParameters(projectCollection)
{
Loggers = new[] { new ConsoleLogger { Verbosity = LoggerVerbosity.Quiet }},
NodeExeLocation = typeof(ProjectFactory).Assembly.Location,
ToolsetDefinitionLocations = projectCollection.ToolsetLocations
};
BuildResult result = BuildManager.DefaultBuildManager.Build(parameters, requestData);
// Build the project so that the outputs are created
if (result.OverallResult == BuildResultCode.Failure)
{
// If the build fails, report the error
throw new CommandLineException(NuGetResources.FailedToBuildProject, Path.GetFileName(_project.FullPath));
}
TargetPath = ResolveTargetPath(result);
}
}
else
{
TargetPath = ResolveTargetPath();
// Make if the target path doesn't exist, fail
if (!File.Exists(TargetPath))
{
throw new CommandLineException(NuGetResources.UnableToFindBuildOutput, TargetPath);
}
}
}