dotnet / roslyn-sdk

Roslyn-SDK templates and Syntax Visualizer
MIT License
512 stars 257 forks source link

Scary Nuget warnings when installing a testing package for .NET 7 #1046

Open DoctorKrolic opened 1 year ago

DoctorKrolic commented 1 year ago

To reproduce:

  1. Create .NET 7 console app
  2. Install Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit v1.1.1 (the latest currently available)
  3. Your .csproj should look like this after 2 previous steps:

    
    <Project Sdk="Microsoft.NET.Sdk">
    
    <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    </PropertyGroup>
    
    <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.1" />
    </ItemGroup>


4. Observe a bunch of Nuget warnings `NU1707: Package '<A bunch of MS.CA packages>' was restored using '<A lot of .NET Framework versions>' instead the project target framework 'net7.0'. This package may not be fully compatible with your project.`

Is that just a scary false-positive, or testing packages are _really_ not supported on non-Windows platforms in 2023?
sharwell commented 1 year ago

You have to separately specify the version of Microsoft.CodeAnalysis you want to use for testing (by adding a package reference with an explicit version). The default/minimum one is Roslyn 1.x, which doesn't have packages compatible with net7.0.

This is by design, as it's required for the testing library to maintain support for Roslyn 1.x.

peteraritchie commented 1 year ago

Is there any work being done to support .NET Core?

sharwell commented 1 year ago

@peteraritchie I don't understand the question. The testing library has supported running tests on .NET Core for years.

DoctorKrolic commented 1 year ago

it's required for the testing library to maintain support for Roslyn 1.x

If not a secret, why? Is it connected with VS 2015 lifecycle?

sharwell commented 1 year ago

There are downstream analyzer packages which are built against an old version of Roslyn, and continue to work well in Visual Studio 2015 while also supporting the latest Visual Studio 2022. Over time there have been a variety of small internal changes in behavior, and it would not be sufficient for those projects to be restricted to testing execution against e.g. Roslyn 4.x+.