在生成后进行的NuGet获取版本 [英] Getting version in post-build for Nuget

查看:123
本文介绍了在生成后进行的NuGet获取版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

if $(ConfigurationName) == Release (
    cd $(ProjectDir)
    nuget spec Entities -f
    nuget pack DeusPak.Entities.csproj -Prop Configuration=Release
    nuget push DeusPak.Entities.$(version).nupkg  $(MYGET_API_KEY) -Source     http://www.myget.org/F/lojaali/api/v2/package
)

我刚才开始玩弄的NuGet,想知道如何纳入我的NuGet包的版本号。我目前硬编码入这显然不是我想继续做的生成后事件。任何人可以帮助

I have just started to play around with NuGet and want to know how to include the version number in my NuGet package. I am currently hard coding it into the post-build event which is obviously not what I want to keep doing. Can anybody help?

这是我目前的生成后事件:

This is my current post-build event :

if $(ConfigurationName) == Release (
    cd $(ProjectDir)
    nuget spec Dev-f
    nuget pack Dev.csproj -Prop Configuration=Release
    nuget push Dev.1.0.0.0.nupkg  $(MYGET_API_KEY) -Source     http://www.myget.org/F/api/v2/package
)

更新:

OK,我设法用正确的汽车打造的DLL增加的版本号:

OK, I have managed to build the DLL with the correct auto incremented version number :

if $(ConfigurationName) == Release (
    cd $(ProjectDir)
    nuget spec Dev -f
    nuget pack Dev.csproj -Prop Configuration=Release
    nuget push Dev.$(version).nupkg  $(MYGET_API_KEY) -Source     http://www.myget.org/F/api/v2/package
)

不过这个版本不我的名单上显示MyGet包。我如何得到它那里展示,因此可以下载?还是这个只能通过手动点击添加包呢?

But this version does not show on my list of MyGet packages. How do I get it to show there so it can be downloaded? Or can this only be done manually by clicking 'Add a package'?

推荐答案

这不是你的问题清楚,但假设的你想与你的程序集的版本同步你的软件包的版本,你可以简单地管理项目的AssemblyInfo.cs文件中的AssemblyVersion属性。

It is not clear in your question, but assuming you want to sync the version of your package with the version of your assembly, you can simply manage the AssemblyVersion attribute in the project's AssemblyInfo.cs file.

[assembly: AssemblyVersion("1.0.0")]

如果你想使用自动生成的内部版本号

or if you want to use auto-generated build numbers

[assembly: AssemblyVersion("1.0.0.*")]

如果您想从集的版本偏离,只有指定包的版本,你可以使用AssemblyInfo.cs文件中 AssemblyInformationalVersion 属性。

If you want to deviate from the assembly's version, and only specify the package version, you can use the AssemblyInformationalVersion attribute in the AssemblyInfo.cs file.

[assembly: AssemblyInformationalVersion("1.0.0")]

这也是从你用的什么版本策略的问题不太清楚,但我会的假设的你想申请的语义版本(其中第一版本3号是最相关的)。通常,当自动创建的NuGet包,我建议你创建一个标记化nuspec文件在你的csproj目录中,这样可以更方便地操纵包的元数据。仅供参考,甚至还有的NuGet包,以帮助您的是:

It's also not clear from the question what versioning strategy you use, but I'll assume you want to apply Semantic Versioning (where the first 3 version numbers are most relevant). In general when auto-creating NuGet packages, I'd recommend you to create a tokenized nuspec file in your csproj directory, so you can more easily manipulate the package metadata. FYI, there's even a NuGet package to assist you with that:

Install-Package NuSpec 

的NuGet会寻找这个nuspec(确保它被称为MyProject.nuspec)时瞄准MyProject.csproj。

NuGet will look for this nuspec (make sure it's called MyProject.nuspec) when targeting MyProject.csproj.

<package>
  <version>$version$</version>
  ...
</package>



我也上的 MyGet 博客在这个岗位:的 http://blog.myget.org/post/2012/04/27/NuGet-version-token-explained.aspx

I also explained this on the MyGet blog in this post: http://blog.myget.org/post/2012/04/27/NuGet-version-token-explained.aspx

一个后生成调用的NuGet包应该是足够好的话,的假设的您只需更改建设前的程序集的版本。

A post build that calls nuget pack should be good enough then, assuming you simply change the assembly version before building.

nuget pack MyProject.csproj

这篇关于在生成后进行的NuGet获取版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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