2

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?

Spikee
  • 3,967
  • 7
  • 35
  • 68

1 Answers1

3

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.

zivkan
  • 12,793
  • 2
  • 34
  • 51
  • Not sure what you mean with SDK style project vs non SKD? The project I'm trying to add this to is .net 4.8 btw. – Spikee Feb 09 '22 at 12:50
  • If your csproj has `Sdk="Microsoft.NET.Sdk"`, or one of the other two syntaxes (https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2022#reference-a-project-sdk), then it's SDK style. If it doesn't (and your csproj lists every .cs file individually), then it's not sdk style and the package doesn't support your project. – zivkan Feb 09 '22 at 13:27
  • Than I think I'm in the not supported camp, I can't find the word sdk anywhere in my csproj file (as you would expect given my question). – Spikee Feb 09 '22 at 15:45
  • Can I change the project to be SDK style? – Spikee Feb 10 '22 at 07:32