2
我正在嘗試使用NuGet核心創建一個NuGet包作爲構建過程的一部分。構建過程創建特定的框架版本,3.5,4.0和4.5。我如何爲每個程序集指定框架版本?創建NuGet包時,如何爲程序集指定框架版本?
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);
}