Reputation: 109
I need to create Coverlet Coverage report using coverlet.collector
, with which afterwards, I want to create HTML report using ReportGenerator
.
I'm having trouble running Coverlet
for .Net Framework 4.8
Class Library NUnit test project in Visual Studio 2017 Professional. The projects .CSPROJ
is converted to Microsoft.NET.SDK
style and inside <TargetFramework>net48</TargetFramework>
is set. The project that I want to run tests against is a WinForms Project targeting .Net Framework 4.6.2
I have also installed .NET 8
and .NET 6
SDKs on my computer as in the documentation for Coverlet
it is noted that .NET 6
or newer is needed. When I try to run dotnet test --collect:"XPlat Code Coverage"
in the project I get the following output:
Determining projects to restore...
Restored <absolute_path_for_current_project>
and the following error
error MSB4019: The imported project "C:\Program Files\dotnet\sdk\8.0.405\Microsoft\VisualStudio\v17.0\WebApplications\Microsoft.WebApplication.targets" was not found.
Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\8.0.405\Microsoft\VisualStudio\v17.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk.
the following (last) part of the given absolute path in the error message is missing (directory structure and files in them) :
\Microsoft\VisualStudio\v17.0\WebApplications\Microsoft.WebApplication.targets
Following is my .CSPROJ
file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Analyzer Include="..\packages\Nunit.Analyzers.2.10.0\analyzers\dotnet\cs\nunit.analyzers.dll" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="172.52.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit.Analyzers" Version="2.10.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Buffers" Version="4.6.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.Memory" Version="4.6.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.6.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=<here_is_relative_path_to_project_I_want_to_test> />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Web" />
</ItemGroup>
</Project>
Note: I do not have Visual Studio 2022 installed.
EDIT 1: I stumbled on this following post https://stackoverflow.com/a/51671875/21175857 which says that there is an issue when Solution contains projects with SDK .CSPROJ
and projects with the old non-SDK .CSPROJ
. So I created a new experimental solution with one Asp.Net Core 2.1 project targeting .Net Framework 4.8 (by default it uses SDK style.CSPROJ
) and another Test Class Library targeting also .net framework 4.8 (also using SDK style .CSPROJ
). When running the same coverlet command dotnet test --collect:"XPlat Code Coverage"
it successfully generated the report.
So now I'm confused. Why does it say in the Coverlet
documentation that it works with >= .Net Framework 4.6.2
. I still need some way to generate coverage be it with Coverlet or something else.
Upvotes: 0
Views: 71