简体   繁体   English

有没有一种从Visual Studio 2015项目自动创建NuGet包的简单方法?

[英]Is there an easy way to automatically create a NuGet package from a Visual Studio 2015 project?

Before Visual Studio 2015, it was trivial to setup your project to automatically generate NuGet packages. 在Visual Studio 2015之前,将项目设置为自动生成NuGet包非常简单。 Specifically, you did: 具体来说,你做了:

  1. Add a .nuspec file to your project .nu​​spec文件添加到项目中
  2. Enable NuGet Package Restore in the Solution right-click context menu 在解决方案右键单击上下文菜单中启用NuGet包还原
  3. Edit the project .csproj file and set the build property <BuildPackage> to true 编辑项目.csproj文件并将构建属性<BuildPackage>为true

And that was it! 就是这样!

However, starting from VS 2015, MSBuild-integrated package restore has been removed and replaced by the new Automatic Package Restore. 但是,从VS 2015开始, 已删除MSBuild集成的程序包还原,并替换为新的自动程序包还原。 While these are all good news, it seems that setting the build property <BuildPackage> to true no longer triggers an automatic package build. 虽然这些都是好消息,但似乎将构建属性<BuildPackage>为true不再触发自动包构建。

This is a major break of functionality! 这是功能的重大突破! Is there a way to setup automatic builds of NuGet without using post-build events? 有没有办法在不使用后期构建事件的情况下设置NuGet的自动构建? Specifically, I'm looking for an MSBuild solution, as it forms the backbone of my build workflow. 具体来说,我正在寻找一个MSBuild解决方案,因为它构成了我的构建工作流程的支柱。

Try OctoPack: https://www.nuget.org/packages/OctoPack/ 试试OctoPack: https ://www.nuget.org/packages/OctoPack/

Just add nuget package to your project. 只需将nuget包添加到您的项目中即可。

If you want to build it every time you build release, add to section <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Whatever' "> next line: 如果您想在每次构建版本时构建它,请添加到<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Whatever' ">下一行:

 <RunOctoPack>true</RunOctoPack>

More information about finetuning can be found here: https://github.com/OctopusDeploy/OctoPack 有关微调的更多信息,请访问: https//github.com/OctopusDeploy/OctoPack

There is a move to Class Library Packages in VS2015 which makes it incredibly easy to create NuGet packages. VS2015中有一个类库包的转移,这使得创建NuGet包非常容易。 I've blogged about this before, but essentially it's just a few steps. 我之前曾在博客上发表过这篇文章,但基本上只是几个步骤。 Note that this is just a RC1 at the moment and not a stable release yet. 请注意,目前这只是一个RC1,而不是一个稳定的版本。

  1. Install the ASP.NET and Web Tools 2015 (RC1 Update 1) update to VS2015. ASP.NET和Web Tools 2015(RC1 Update 1)更新安装到VS2015。

  2. Open VS2015 and create a new Class Library Package project. 打开VS2015并创建一个新的类库包项目。

类库包

  1. Add your code to the library and configure the project.json file with any changes you may need. 将代码添加到库中,并使用您可能需要的任何更改配置project.json文件。 A default project.json file is used as an example. 默认的 project.json文件为例。

  2. Right-click on the project and select the Properties menu item. 右键单击项目,然后选择“属性”菜单项。 In the Build tab select “Produce outputs on build”. 在“构建”选项卡中,选择“在构建时生成输出”。 Build the project. 建立项目。

产生输出

You're done. 你完成了。 Go to the artifacts folder in your project, in my case “artifacts\\bin\\AwesomeSoft.TextConverter\\Debug”. 转到项目中的artifacts文件夹,在我的例子中是“artifacts \\ bin \\ AwesomeSoft.TextConverter \\ Debug”。

You should see the NuGet package already created, and the folders targeting each framework specified earlier. 您应该看到已经创建的NuGet包,以及针对之前指定的每个框架的文件夹。

最终的nuspec

There is another alternative called NuPack : 还有另一个名为NuPack的替代方案:

How-to-create-a-nuget-package-on-each-Visual-Studio-with-NuPack 如何对创建-A-的NuGet-封装上的每个视听工作室与- NuPack

It is a nuget package that automatically generate nuget package on build time. 它是一个nuget包,可以在构建时自动生成nuget包。

VS4MAc already supports this and you can get it as a extension for VS on Windows VS4MAc已经支持此功能,您可以将其作为Windows上VS的扩展

https://github.com/NuGet/NuGet.Build.Packaging https://github.com/NuGet/NuGet.Build.Packaging

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Visual Studio 2017 RC中的.NET Core MSBuild项目创建NuGet包? - How do you create a NuGet package from a .NET Core MSBuild project in Visual Studio 2017 RC? 自动将 NuGet package 中的文件链接到项目中 - Link files from a NuGet package into a project automatically 从Visual Studio 2010项目文件为多个框架目标构建NuGet包 - Build NuGet package for multiple framework targets from Visual Studio 2010 project file Visual Studio 2017和nuget包 - Visual studio 2017 and nuget package 如何更改 Visual Studio 项目中的 NuGet 包引用以使用 Nuget.config - How to change the NuGet-package reference in a Visual Studio project to use Nuget.config 在Visual Studio项目中使用“ nuget pack”时,覆盖nuget包名称 - Overriding nuget package name when using “nuget pack” with a visual studio project 保存后自动构建,适用于Visual Studio 2015? - Automatically Build after save, for Visual Studio 2015? 我将项目从Visual Studio 2010升级到了Visual Studio 2015,但是我需要升级msbuild - I upgraded my project from visual studio 2010 to visual studio 2015 but i is there any need to upgrade the msbuild 无法在 Visual Studio 2015 中加载 CS 项目 - Unable to load CS project in Visual Studio 2015 Visual Studio 2015 项目构建失败但没有错误 - Visual Studio 2015 project builds failed but no errors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM