软件包版本始终为 1.0.0,带有 dotnet pack [英] Package version is always 1.0.0 with dotnet pack
问题描述
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 升级到 TFS 2017.结果是,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.
然而,尽管 AssemblyVersion
和 AssemblyFileVersion
在 AssemblyInfo.cs
中设置为正确的内部版本号 - 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 迁移文档,您可以使用 VersionPrefix
和 VersionSuffix
属性.
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>
这篇关于软件包版本始终为 1.0.0,带有 dotnet pack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!