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 would generate a NUPKG file with a version like 1.0.6604.1234
appending the date number and a build ID.
NET Standard issues
In .NET Core and .NET standard the new .csproj
format does not support this wildcard format.
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).
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.
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.
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?