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);
}
}
}
private PackageDependency CreateDependencyFromProject(Project project) { try { var projectFactory = new ProjectFactory(project); projectFactory.Build = Build; projectFactory.ProjectProperties = ProjectProperties; projectFactory.BuildProject(); var builder = new PackageBuilder(); try { AssemblyMetadataExtractor.ExtractMetadata(builder, projectFactory.TargetPath); } catch { projectFactory.ExtractMetadataFromProject(builder); } projectFactory.InitializeProperties(builder); projectFactory.ProcessNuspec(builder, null); return(new PackageDependency( builder.Id, VersionUtility.ParseVersionSpec(builder.Version.ToString()))); } catch (Exception ex) { var message = string.Format( CultureInfo.InvariantCulture, NuGetResources.Error_ProcessingNuspecFile, project.FullPath, ex.Message); throw new CommandLineException(message, ex); } }