[英]How to create a NuGet Package using NuGet.Core?
I would like to create a application which makes use of the NuGet Package NuGet.Core. 我想创建一个使用NuGet包NuGet.Core的应用程序。 It has a class called PackageBuilder that makes it possible.
它有一个名为PackageBuilder的类,使其成为可能。 Is there any sample / tutorial / documentation available?
有没有可用的样本/教程/文档?
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. 基于David代码的改进示例。 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); }
I am not aware of any tutorial or documentation on how to build a NuGet package using NuGet.Core. 我不知道有关如何使用NuGet.Core构建NuGet包的任何教程或文档。 Instead I would take a look at the source code for NuGet.exe.
相反,我会看一下NuGet.exe的源代码。 It has a pack command that builds a package from a .nuspec file.
它有一个pack命令,可以从.nuspec文件构建一个包。 The PackCommand class , which uses the PackageBuilder class, should show you what you need to do.
使用PackageBuilder类的PackCommand类应该向您展示您需要做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.