我想创建一个使用NuGet包NuGet.Core的应用程序。 它有一个名为PackageBuilder的类,使其成为可能。是否有可用的样本/教程/文档?
答案 0 :(得分:35)
一个非常简单的例子:
写一些这样的代码:
ManifestMetadata metadata = new ManifestMetadata()
{
Authors = "mauvo",
Version = "1.0.0.0",
Id = "myPackageIdentifier",
Description = "A description",
};
PackageBuilder builder = new PackageBuilder();
builder.PopulateFiles("folderPath/", new[] {new ManifestFile() {Source = "**"}});
builder.Populate(metadata);
using(FileStream stream = File.Open(packagePath, FileMode.OpenOrCreate))
{
builder.Save(stream);
}
答案 1 :(得分:7)
基于David代码的改进示例。变化:
定义包文件名的行。
ManifestMetadata metadata = new ManifestMetadata()
{
Authors = "mauvo",
Version = "1.0.0.0",
Id = "myPackageIdentifier",
Description = "A description",
};
PackageBuilder builder = new PackageBuilder();
var files = Directory.GetFiles(packagePath, "*", SearchOption.AllDirectories)
.Where(f => !f.EndsWith(".nuspec"))
.Select(f => new ManifestFile { Source = f, Target = f.Replace(path, "") })
.ToList();
builder.PopulateFiles("", files);
builder.Populate(metadata);
string packageFile = Path.Combine(packagePath, builder.GetFullName()) + ".nupkg";
using(FileStream stream = File.Open(packageFile, FileMode.OpenOrCreate))
{
builder.Save(stream);
}
答案 2 :(得分:2)
我不知道有关如何使用NuGet.Core构建NuGet包的任何教程或文档。相反,我会看一下NuGet.exe的源代码。它有一个 pack 命令,用于从.nuspec文件构建包。使用PackageBuilder类的PackCommand class应该向您展示您需要做什么。