自动发布使用VS2017构建的NuGet软件包 [英] Automatically publish a NuGet package built with VS2017

查看:95
本文介绍了自动发布使用VS2017构建的NuGet软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 2017中的新增功能是能够针对某些目标类型(即 .NET Standard 2.0 这是我正在使用的)在生成时生成NuGet软件包的功能。 。

New in Visual Studio 2017 is the ability to generate a NuGet package on build for some target types (namely, .NET Standard 2.0 which is what I'm using).

这很好用,并且 .nupkg 文件是在成功构建时生成的。

This works great, and the .nupkg file is generated on successful build.

但是,我无法弄清楚如何将生成的软件包自动发布到我们的本地存储库中。

However, I'm not able to figure out how to get the built package automatically published to our local repository.

我已经尝试过构建后事件:

I already tried a post-build event of:

nuget push -Source https://my.nuget.server/nuget/ "C:\Source\MyProject\bin\Release\MyProject.1.0.0.nupkg"

但这会带来2个问题:


  1. 软件包名称包含版本号,并且不能作为构建后事件使用变量,所以我不能说例如 nuget push $(NugetPackage)。我也想不出可以使我有效获得程序包名称的宏/变量组合。

  2. 自动NuGet打包过程发生在构建后事件之后
  3. em>,因此在生成后,该软件包甚至还没有生成!
  1. The name of the package includes the version number and this isn't available as a post-build event variable, so I can't say, for example, nuget push $(NugetPackage). I also can't figure out a combination of macros/variables that would get me the package name effectively.
  2. The automatic NuGet packaging process occurs after the post-build event, so at the time of post-build, the package has not even been generated yet!

Microsoft提供了这一功能- ass自动NuGet打包,但是没有办法将其推送到本地存储库(或看起来)!

Microsoft has provided this kick-ass automatic NuGet packaging, but no way to push it to a local repository (or so it seems)!

有人能使用它吗?我想念什么吗?有解决方法吗?

Has anyone gotten this to work? Am I missing something? Is there a workaround? Is this something being worked on?

推荐答案

您可以通过将以下行添加到库中来自动发布到nuget: csproj 。您需要将环境变量设置为nuget.exe的位置,或者将该位置添加到系统的PATH中,或者将其硬输入到 Command 参数中。

You can automate a publish to nuget by adding the below line to your libraries csproj directly. You will need to either set an environment variable to the location of your nuget.exe, add the location to your system's PATH, or hard enter it into the Command parameter.

我个人更喜欢下载最新版本的nuget.exe ,并将其放入用户的%userprofile%\.nuget 文件夹中。 nuget在这里存储软件包的本地缓存,因此应该已经创建了。

Personally, I prefer to download the latest version of nuget.exe and place it into the user's %userprofile%\.nuget folder. This is where nuget stores the local cache of packages, so it should be already created.

发布到远程存储库的示例。

Example of publishing to a remote repository.

<Target Name="PostPackNugetDeploy" AfterTargets="Pack" Condition="'$(Configuration)' == 'Release'">
  <Exec Command="="%userprofile%\.nuget\nuget.exe push &quot;$(OutputPath)$(PackageId).$(PackageVersion).nupkg&quot; -Source &quot;$(NuGetSourceRelease)&quot; -Verbosity Detailed" />
</Target>

发布到a的示例

<Target Name="PostPackNugetDeploy" AfterTargets="Pack" Condition="'$(Configuration)' == 'Release'">
 <Exec Command="%userprofile%\.nuget\nuget.exe add &quot;$(OutputPath)$(PackageId).$(PackageVersion).nupkg&quot; -source \\Server\Packages" />
</Target>

您可以在此处 https:上找到有关nuget的MSBuild目标上的文档: //docs.microsoft.com/zh-cn/nuget/reference/msbuild-targets

我已经将其包装到一个可以在您的项目中引用的nuget包中。它可以处理所有这些,您要做的就是在项目中添加一个属性。

I have wrapped this into a nuget package that can be referenced within your project. It takes care of all this, all you have to do is add a property to your project.

您可以在此处完善代码和完整指南。

https://github.com/SimplerSoftware/SS.NuGet.Publish

You can fine the code and full guide here.
https://github.com/SimplerSoftware/SS.NuGet.Publish

这篇关于自动发布使用VS2017构建的NuGet软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆