使用 'dotnet pack' 时无效 'PackageVersion'

Invalid 'PackageVersion' when using 'dotnet pack'

使用 dotnet pack 创建工件时,当我的 SemVer 包版本中的预发布标识符之一以 0 开头时,任务失败。

这是 dotnet pack 的已知错误吗?有任何修复吗?

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]

错误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似乎符合。

在这种情况下,导致问题的部分是 088820,这是 Git 提交哈希的前 6 个字符,因此我无法更改它。

这里的答案似乎是 dotnet 用于验证 PackageVersion 是有效 SemVer 版本的任何包都存在错误。

如果使用 <dot-separated pre-release identifiers> 并且以下对于点 . 之后的任何标识符都是正确的,那么该版本将被视为无效的 SemVer。

  • 0 开头。
  • 长度大于一个字符。
  • 不包含任何字母[a-f]

例如,1.0.8-INF-2382.9.088820无效,但1.0.8-INF-2382.9.0888a0有效。

在Python中导入SemVer时也是如此。这失败了 -

print(semver.VersionInfo.parse(1.0.8-INF-2382.9.088820))

ValueError: 1.0.8-INF-2382.9.088820 is not valid SemVer string

但这行得通 -

print(semver.VersionInfo.parse(1.0.8-INF-2382.9.0888a0))

1.0.8-INF-2382.9.0888a0