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 / documentation available?
我想创建一个使用NuGet包NuGet.Core的应用程序。它有一个名为PackageBuilder的类,使其成为可能。有没有可用的样本/教程/文档?
3 个解决方案
#1
2
I am not aware of any tutorial or documentation on how to build a NuGet package using NuGet.Core. Instead I would take a look at the source code for NuGet.exe. It has a pack command that builds a package from a .nuspec file. The PackCommand class, which uses the PackageBuilder class, should show you what you need to do.
我不知道有关如何使用NuGet.Core构建NuGet包的任何教程或文档。相反,我会看一下NuGet.exe的源代码。它有一个pack命令,可以从.nuspec文件构建一个包。使用PackageBuilder类的PackCommand类应该向您展示您需要做什么。
#2
34
A really simple example:
一个非常简单的例子:
- create a folder containing the files you want in your package.
- 创建一个包含所需文件的文件夹。
-
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); }
#3
7
An improved example based on David's code. Changes:
基于David代码的改进示例。变化:
- All files in a folder except *.nuspec are added to package.
- 除* .nuspec之外的文件夹中的所有文件都将添加到包中。
-
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); }
#1
2
I am not aware of any tutorial or documentation on how to build a NuGet package using NuGet.Core. Instead I would take a look at the source code for NuGet.exe. It has a pack command that builds a package from a .nuspec file. The PackCommand class, which uses the PackageBuilder class, should show you what you need to do.
我不知道有关如何使用NuGet.Core构建NuGet包的任何教程或文档。相反,我会看一下NuGet.exe的源代码。它有一个pack命令,可以从.nuspec文件构建一个包。使用PackageBuilder类的PackCommand类应该向您展示您需要做什么。
#2
34
A really simple example:
一个非常简单的例子:
- create a folder containing the files you want in your package.
- 创建一个包含所需文件的文件夹。
-
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); }
#3
7
An improved example based on David's code. Changes:
基于David代码的改进示例。变化:
- All files in a folder except *.nuspec are added to package.
- 除* .nuspec之外的文件夹中的所有文件都将添加到包中。
-
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); }