问题描述
使用.NET Framework库,您可以使用通配符指定版本,并且在VSTS中运行NUGET生成任务时,NUGET pack命令会自动附加生成日期和版本。
With a .NET Framework library you could specify a version with a wildcard and NUGET pack command would append the build date and version automatically when running a NUGET Build Task in VSTS.
[assembly:AssemblyVersion( 1.0。*)]
NUGET PACK将生成一个NUPKG文件带有 1.0.6604.1234
之类的版本,并附加日期编号和内部版本ID。
NUGET PACK would generate a NUPKG file with a version like 1.0.6604.1234
appending the date number and a build ID.
在.NET Core和.NET标准中,新的 .csproj
格式不支持此通配符格式。
In .NET Core and .NET standard the new .csproj
format does not support this wildcard format.
我们无法与Nuget.exe打包(原因:),但我们可以使用 dotnet包
,除非我需要自动增加内部版本号。 VSTS中的 dotnet
构建任务允许我完全替换版本号,但是我想将版本保留在csproj文件中,而只是附加一个内部版本号(如我以前使用的
We can't package with Nuget.exe (reason: this issue) but we can use dotnet pack
except I need to auto-increment the build numbers. The dotnet
Build Task in VSTS allows me to wholly replace the version number, but I want to retain the version in the csproj file, and just append a build number (as I used to).
我发现在csproj文件中使用< VersionPrefix> x.y< / VersionPrefix>
将与 nuget pack
一起使用,然后我可以将附加参数 VersionSuffix = $(Build.BuildNumber)
添加到包中任务。
I found that using <VersionPrefix>x.y</VersionPrefix>
in the csproj file would work with nuget pack
and I could then add the additional parameter VersionSuffix=$(Build.BuildNumber)
to the pack task.
在第一个开发人员在项目属性对话框中更新项目版本之前,一切看起来都很不错。 Visual Studio忽略了VersionPrefix并设置了< Version>
标记-生成号修订被忽略,因为 Version
标签存在。
All looked good until the first dev updated the project version in the project properties dialog. Visual Studio ignored the VersionPrefix and set the <Version>
tag - and the build number fix is ignored because a Version
tag exists.
是否可以从csproj读取版本
?如果是这样,我可以将build属性设置为 Version = $(ProjectVersion)。$(Build.BuildNumber)
?
Is there a way to read the Version
from the csproj? If so I could set the build property to Version=$(ProjectVersion).$(Build.BuildNumber)
?
或者在打包时还有其他方法可以自动增加构建版本?
Or are there alternative ways to handle auto-incrementing the build version when packaging?
推荐答案
感谢@ patricklu-msft
Thanks to @patricklu-msft for his suggestions.
似乎没有内置的方法来模拟我们以前在 NUGET包
中使用的通配符行为 dotnet包
,也没有办法从项目文件中删除< Version>
标记。
There is it appears no built-in way to emulate the wildcard behaviour we previously had NUGET pack
with dotnet pack
, nor was there way to get the <Version>
tag out of the project file.
因此,我创建了一个新的VSTS Build任务,它执行以下操作:。
So I've created a new VSTS Build task that does this: VersionTaskReader in the MarketPlace.
此扩展名可以指向 .csproj
或 .vbproj
并将设置环境变量 VERSION
和 VERSION_BUILD
具有 BUILDID
appe nded。
This extension can be pointed to a .csproj
or .vbproj
and will set an environment variable VERSION
, and VERSION_BUILD
which has the BUILDID
appended. You can optionally add a prefix to make each instance different if needed.
例如,如果您的项目包含< Version> 1.1< /版本>
,则 VERSION_BUILD
类似于 1.1.8680
For example, if your project contains <Version>1.1</Version>
then the VERSION_BUILD
would be something like 1.1.8680
然后, dotnet pack
任务可以在版本控制中使用环境变量 VERSION_BUILD
选项屏幕,以便内部版本号自动递增。
Then the dotnet pack
task can use the environment variable VERSION_BUILD
in the versioning options screen, so that the build number automatically increments.
这篇关于在VSTS生成过程中,将生成号添加到具有`dotnet pack`的软件包版本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!