I would like to create a application which makes use of the NuGet Package NuGet.Core. It has a class called PackageBuilder that makes it possible. Is there any sample / tutorial
A really simple example:
Write some code like this:
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);
}
An improved example based on David's code. Changes:
A row defining package file name.
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);
}