Unable to add coverlet nuget package(s) - Version string portion was too short or too long

Viewed 273

When I try to add coverlet.msbuild to my test project I get this error:

The expression "[System.Version]::Parse('')" cannot be evaluated. Version string portion was too short or too long.  C:\my_repo\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.targets              

I do see changes to my csproj:

<Import Project="..\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.props" Condition="Exists('..\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.props')" />

<Error Condition="!Exists('..\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.props'))" />
<Error Condition="!Exists('..\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.targets'))" />

<Import Project="..\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.targets" Condition="Exists('..\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.targets')" />

But no changes to packages.config, so it looks like the nuget isn't actually installed.

I'm trying to add this to a .net 4.8 test project.

Any ideas to what may cause this?

1 Answers

The error message tells you that the error is coming from C:\my_repo\packages\coverlet.msbuild.3.1.2\build\coverlet.msbuild.targets. So let's take a look at it. Since Coverlet is open source, I can link to its source: https://github.com/coverlet-coverage/coverlet/blob/1e74dd43824fc49e90622a3442133c2d9f4e8e01/src/coverlet.msbuild.tasks/coverlet.msbuild.targets (current master branch commit, using permalink just in case the file changes in the future)

Since the error talks about System.Version, we can search for it, and we find it near the top, on line 11. It's trying to parse two properties, _CoverletSdkNETCoreSdkVersion and _CoverletSdkMinVersionWithDependencyTarget. The first property is defined as _CoverletSdkNETCoreSdkVersion>$(NETCoreSdkVersion)</_CoverletSdkNETCoreSdkVersion>.

Therefore I conclude that the package author only intends to support SDK sytle projects, not ".NET Framework" (non-sdk) style projects. They just implemented it in a way that crashes their code in non-sdk style projects.

Note that you can still target the .NET Framework using an SDK style project. Create a ".NET" (new branding for .NET Core since .NET 5) test project, then edit the csproj and change <TargetFramework>net6.0</TargetFramework> to <TargetFramework>net48</TargetFramework>.

I don't know why coverlet isn't in your packages.config, the package installation seems successful, it's only failing at build time, which does not happen until install is finished.

Related