带有dotnet pack的软件包版本始终为1.0.0 [英] Package version is always 1.0.0 with dotnet pack

查看:79
本文介绍了带有dotnet pack的软件包版本始终为1.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR:dotnet pack在为程序集创建nuget程序包时在哪里提取版本信息?

TLDR: Where is dotnet pack pulling the version information when it creates the nuget package for an assembly?

我有一个库,该库已经通过project.json从.NET 4.6.1项目过渡到了.NET Core项目.对于此期间的CI(使用TFS 2015 vnext),我将获取我的版本号,并将project.json文件中的版本号替换为新版本. dotnet pack命令可以很好地选择版本,并使用更新的版本号创建一个新软件包.

I have a library, that I had transitioned from a .NET 4.6.1 project to a .NET Core project with project.json. For my CI during this period (using TFS 2015 vnext), I would get my version number and replace the version number in the project.json file with the new version. The dotnet pack command would pick the version up just fine, and create a new package with the updated version number.

上周,我从TFS 2015升级到TFS2017.事实证明,project.json被更新的.csproj文件替换.我已经更新了CI.在我的CI期间-我更新了/Properties/AssemblyInfo.cs文件,将AssemblyVersion标记替换为当前版本的版本.然后,我构建解决方案-一切正常.然后,我打包解决方案.

Last week, I upgraded from TFS 2015 to TFS 2017. Turns out, project.json was replaced with an updated .csproj file. I've updated my CI. During my CI - I update my /Properties/AssemblyInfo.cs file, replacing the AssemblyVersion tag with the version for the current build. Then I build the solution - which builds just fine. Then I package the solution.

但是,尽管在AssemblyInfo.cs中将AssemblyVersionAssemblyFileVersion设置为正确的内部版本号-dotnet pack仍在生成*.1.0.0.nupkg的.nupkg文件.

However, despite the AssemblyVersion and AssemblyFileVersion being set in AssemblyInfo.cs to the correct build number - dotnet pack is still producing .nupkg files that are *.1.0.0.nupkg.

我想念什么?

这是我的背包命令:

dotnet pack $projectFile -o $currentDirectory

推荐答案

使用dotnet pack时,版本是从项目定义(以前是project.json,现在是*.csproj)而不是AssemblyInfo.cs中提取的.因此,您的新工作流程将与project.json的工作流程非常相似.

When you use dotnet pack, the version is pulled from the project definition (previously project.json, now *.csproj), not AssemblyInfo.cs. So, your new workflow will be very similar to what it was with project.json.

来自项目. json到csproj迁移文档,则可以使用VersionPrefixVersionSuffix属性.

From the project.json to csproj migration docs, you can use the VersionPrefix and VersionSuffix properties.

之前:

{
  "version": "1.0.0-alpha-*"
}

现在:

<PropertyGroup>
  <VersionPrefix>1.0.0</VersionPrefix>
  <VersionSuffix>alpha</VersionSuffix>
</PropertyGroup>

您还可以使用单个Version属性,但是文档警告说,这可能会在打包过程中覆盖版本设置".

You can also use the single Version property, but the docs warn that this "may override version settings during packaging".

<PropertyGroup>
  <Version>1.0.0-alpha</Version>
</PropertyGroup>

这篇关于带有dotnet pack的软件包版本始终为1.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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