Versioning issues with dotnet core pack and VSTS 2017

I'm currently working on a number of dotnet core applications and figuring out how to build and package them for placement into nuget repositories such as Nexus, Artifactory, VSTS Packages etc.

One thing that has been problematic has been creating an acceptable version number for the nuget package of a dotnet core class library project.

In short, the version number that you are able to nuget pack (e.g. 1.0.0-100) isn't compatible with the nuget repository.

I initially attempted to tweak to the nuget pack command by adding a --version-suffix=$(Build.BuildId) as an argument.

Oddly, you can build the package but you can't store them - here is the build output from VSTS when pushing the build package into it's own VSTS Packages Repo:

'1.0.0-214' is not a valid version string.
Parameter name: version
Error: C:\a\_tasks\NuGetPublisher_333b11bd-d341-40d9-afcf-b32d5ce6f25b\0.2.30\node_modules\nuget-task-common\NuGet\3.3.0\NuGet.exe failed with return code: 1
Packages failed to publish

I think this has something to do with nuget not entirely supporting semver.

As this didn't work, I finally succeeded by adding a new powershell task right at the start of the build to modify the project.json file appropriately.

cat $ProjectJsonPath

(Get-Content $ProjectJsonPath).replace('1.0.0-*', '1.0.$(Build.BuildId)') | Set-Content $ProjectJsonPath
cat $ProjectJsonPath

Once the project.json file is correct, you can proceed to nuget restore,nuget build,nuget pack and finally store the resulting nuget package into your choice of nuget repository.

I admit the solution isn't pretty, but it works - and I'm sure the versioning of dotnet core class libraries will be sorted in due course.

comments powered by Disqus