When using dotnet pack
to create an artefact, the task is failing when one of the pre-release identifiers in my SemVer package version starts with 0
.
Is this a known bug with dotnet pack
, and is there any fix for it?
1.0.8-INF-2382.9.088820
Microsoft (R) Build Engine version 16.10.0+4242f381a for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
/usr/share/dotnet/sdk/5.0.300/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018: The "GetPackOutputItemsTask" task failed unexpectedly. [/home/dgard/repos/ldx-analytics-infrastructure/.jenkins/ldx.analytics.infrastructure/ldx.analytics.infrastructure.csproj]
/usr/share/dotnet/sdk/5.0.300/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018: System.ArgumentException: PackageVersion string specified '1.0.8-INF-2382.9.088820' is invalid. [/home/dgard/repos/ldx-analytics-infrastructure/.jenkins/ldx.analytics.infrastructure/ldx.analytics.infrastructure.csproj]
/usr/share/dotnet/sdk/5.0.300/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018: at NuGet.Build.Tasks.Pack.GetPackOutputItemsTask.Execute() [/home/dgard/repos/ldx-analytics-infrastructure/.jenkins/ldx.analytics.infrastructure/ldx.analytics.infrastructure.csproj]
/usr/share/dotnet/sdk/5.0.300/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/home/dgard/repos/ldx-analytics-infrastructure/.jenkins/ldx.analytics.infrastructure/ldx.analytics.infrastructure.csproj]
/usr/share/dotnet/sdk/5.0.300/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets(110,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/home/dgard/repos/ldx-analytics-infrastructure/.jenkins/ldx.analytics.infrastructure/ldx.analytics.infrastructure.csproj]
The error MSB4018
is pretty generic, but some Googling led me to NU5024
which suggests that the version number is not SemVer compliant. However, I believe that it is valid, and online SemVer checkers seem to agree.
In this case, the portion that is causing the issue is 088820
, which is the first 6 characters of the Git commit hash, so it's not something that I can change.
The answer here seems to be that there is a bug with whatever package dotnet
is using to validate that the PackageVersion
is a valid SemVer version.
If using <dot-separated pre-release identifiers>
and the following are all true for any identifier that follows a dot .
, then the version is seen as not being valid SemVer.
0
.[a-f]
.For example, 1.0.8-INF-2382.9.088820
is invalid, but 1.0.8-INF-2382.9.0888a0
is valid.
The same is true when importing SemVer
in Python. This fails -
print(semver.VersionInfo.parse(1.0.8-INF-2382.9.088820))
ValueError: 1.0.8-INF-2382.9.088820 is not valid SemVer string
But this works -
print(semver.VersionInfo.parse(1.0.8-INF-2382.9.0888a0))
1.0.8-INF-2382.9.0888a0