Reputation: 3357
I am trying to create a basic NuGet package programmatically using Nuget.core API.
Firstly I populate Metadata and Files field of NuSpec manifest file:
Manifest nuspec = new Manifest(); //creating a nuspec
ManifestMetadata metaDataLocal = new ManifestMetadata()
{
Authors = "mauvo",
Version = "1.0.0.0",
Id = "myPackageIdentifier",
Description = "A description",
};
nuspec.Metadata = metaDataLocal; //populating nuspec's metadata
ManifestFile mf = new ManifestFile();
mf.Source = "bin\\Debug\\DX11VideoRenderer.dll";
mf.Target = "lib";
List<ManifestFile> listManifestFile = new List<ManifestFile>();
listManifestFile.Add(mf);
nuspec.Files = listManifestFile; //populating nuspec's Files field
Then I use package builder class to create the package and save it to the debug folder of my project:
PackageBuilder builder = new PackageBuilder()
{
Id = "1",
Description = "Some test package"
};
builder.Populate(nuspec.Metadata);
foreach (ManifestFile value in nuspec.Files)
{
builder.PopulateFiles(value.Target, nuspec.Files);
builder.Files.Add(new PhysicalPackageFile()
{
SourcePath = value.Target,
TargetPath = @"lib\"
});
}
using (FileStream stream = File.Open("bin\\Debug", FileMode.OpenOrCreate))
{
builder.Save(stream);
}
I have hardcoded all the source paths, destination path, package info and metadata. But for some reason the package is not being created. Code runs without any errors.
Upvotes: 1
Views: 1567
Reputation: 4229
I would guess it is probably being saved, but the file's name is Debug
rather than x.nupkg
.
using (FileStream stream = File.Open("bin\\Debug", FileMode.OpenOrCreate))
{ ^^^^^^^^^^^^
builder.Save(stream);
}
Upvotes: 1