public PackageBuilder CreateBuilder(string basePath)
{
BuildProject();
Logger.Log(MessageLevel.Info, NuGetResources.PackagingFilesFromOutputPath, Path.GetDirectoryName(TargetPath));
var builder = new PackageBuilder();
try
{
// Populate the package builder with initial metadata from the assembly/exe
AssemblyMetadataExtractor.ExtractMetadata(builder, TargetPath);
}
catch
{
Logger.Log(MessageLevel.Warning, NuGetResources.UnableToExtractAssemblyMetadata, Path.GetFileName(TargetPath));
ExtractMetadataFromProject(builder);
}
// Set the properties that were resolved from the assembly/project so they can be
// resolved by name if the nuspec contains tokens
_properties.Clear();
_properties.Add("Id", builder.Id);
_properties.Add("Version", builder.Version.ToString());
if (!String.IsNullOrEmpty(builder.Title))
{
_properties.Add("Title", builder.Title);
}
if (!String.IsNullOrEmpty(builder.Description))
{
_properties.Add("Description", builder.Description);
}
string projectAuthor = builder.Authors.FirstOrDefault();
if (!String.IsNullOrEmpty(projectAuthor))
{
_properties.Add("Author", projectAuthor);
}
// If the package contains a nuspec file then use it for metadata
Manifest manifest = ProcessNuspec(builder, basePath);
// Remove the extra author
if (builder.Authors.Count > 1)
{
builder.Authors.Remove(projectAuthor);
}
// Add output files
AddOutputFiles(builder);
// if there is a .nuspec file, only add content files if the <files /> element is not empty.
if (manifest == null || manifest.Files == null || manifest.Files.Count > 0)
{
// Add content files
AddFiles(builder, ContentItemType, ContentFolder);
}
// Add sources if this is a symbol package
if (IncludeSymbols)
{
AddFiles(builder, SourcesItemType, SourcesFolder);
}
ProcessDependencies(builder);
// Set defaults if some required fields are missing
if (String.IsNullOrEmpty(builder.Description))
{
builder.Description = "Description";
Logger.Log(MessageLevel.Warning, NuGetResources.Warning_UnspecifiedField, "Description", "Description");
}
if (!builder.Authors.Any())
{
builder.Authors.Add(Environment.UserName);
Logger.Log(MessageLevel.Warning, NuGetResources.Warning_UnspecifiedField, "Author", Environment.UserName);
}
return builder;
}