我正在尝试使用 NuGet 核心创建 NuGet 包作为构建过程的一部分。构建过程会创建特定的框架版本 3.5、4.0 和 4.5。如何为每个程序集指定框架版本?
public void Create(Package package)
{
if (String.IsNullOrEmpty(package.Id))
throw new ArgumentException("package.Id is required", "package");
if (String.IsNullOrEmpty(package.Version))
throw new ArgumentException("package.Version is required", "package");
if (String.IsNullOrEmpty(package.Authors))
throw new ArgumentException("package.Authors is required", "package");
if (String.IsNullOrEmpty(package.Description))
throw new ArgumentException("package.Description is required", "package");
if (package.Files == null || package.Files.Count == 0)
throw new ArgumentException("package.Files cannot be empty", "package");
ManifestMetadata metadata = new ManifestMetadata();
metadata.Id = package.Id;
metadata.Version = package.Version;
metadata.Title = package.Title;
metadata.Authors = package.Authors;
metadata.Owners = package.Authors;
metadata.IconUrl = package.IconUrl;
metadata.ProjectUrl = package.ProjectUrl;
metadata.RequireLicenseAcceptance = true;
metadata.LicenseUrl = package.LicenseUrl;
metadata.Summary = package.Summary;
metadata.Description = package.Description;
metadata.Copyright = package.Copyright;
metadata.Language = "en-US";
metadata.Tags = package.Tags;
metadata.ReleaseNotes = package.ReleaseNotes;
List<ManifestFile> manifestFiles = new List<ManifestFile>();
foreach (var file in package.Files)
{
ManifestFile manifestFile = new ManifestFile();
manifestFile.Source = Path.GetFileName(file);
manifestFile.Target = @"lib\" + Path.GetFileName(file);
manifestFiles.Add(manifestFile);
}
PackageBuilder builder = new PackageBuilder();
builder.PopulateFiles(ExtractPath(package.Files[0]), manifestFiles);
builder.Populate(metadata);
using (FileStream stream = File.Open(package.PackagePath, FileMode.OpenOrCreate))
{
builder.Save(stream);
}
}
private static string ExtractPath(string fullPath)
{
if (fullPath.Length == 0)
throw new ArgumentNullException("fullPath");
//Account for already in form of path
if (String.IsNullOrEmpty(Path.GetFileName(fullPath))
|| String.IsNullOrEmpty(Path.GetExtension(fullPath)))
{
return fullPath;
}
return Path.GetDirectoryName(fullPath);
}