dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

Unable to load Analyzer assembly in .NET 6.0 #53476

Closed TanvirArjel closed 3 years ago

TanvirArjel commented 3 years ago

Suddenly I am receiving the following warning and error:

Warning:

Unable to load Analyzer assembly C:\Users\TanvirArjel\.nuget\packages\microsoft.extensions.logging\5.0.0\analyzers\dotnet\cs\Microsoft.Extensions.Logging.Generators.dll: Could not find a part of the path 'C:\Users\TanvirArjel\.nuget\packages\microsoft.extensions.logging\5.0.0\analyzers\dotnet\cs\Microsoft.Extensions.Logging.Generators.dll'.

Error:

CSC : error CS0006: Metadata file 'C:\Users\TanvirArjel\.nuget\packages\microsoft.extensions.logging\5.0.0\analyzers\dotnet\cs\Microsoft.Extensions.Logging.Generators.dll' could not be found [D:\GitHub\EFCore.GenericRepository\src\TanvirArjel.EFCore.GenericRepository.csproj]

Project files is:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
    <LangVersion>8.0</LangVersion>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <AnalysisMode>AllEnabledByDefault</AnalysisMode>-->
    <AssemblyName>TanvirArjel.EFCore.GenericRepository</AssemblyName>
    <RootNamespace>TanvirArjel.EFCore.GenericRepository</RootNamespace>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0-*" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.*" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.*" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.*" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.*" />
  </ItemGroup>

</Project>

If I remove .NET 6.0 from TargetFrameworks then both warning and error go away.

However, How can I fix the issue right now without removing .NET 6.0 support?

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

SimonCropp commented 3 years ago

more context: here is the repo https://github.com/TanvirArjel/EFCore.GenericRepository and here is the commit that should fail https://github.com/TanvirArjel/EFCore.GenericRepository/commit/0323871b35e5a49c197a83e1869ccf74c7a7a110

as for the bug, it is weird. so only v6 of microsoft.extensions.logging has analyzers. ie earlier versions do not. so it seems to be conflating "v6 has analyzers" with "the microsoft.extensions.logging nuget has analyzers"

@TanvirArjel as for a solution for you.... the current assumption of TanvirArjel.EFCore.GenericRepository is that: wanting to consume a certain version of the runtime implies someone wants to ref a corresponding version of ef. this is not correct. eg i might want to use ef 3 on net 6. So i recommend either only supporting one version of ef, or (if u want to keep supporting many) release named nugets that correspond to the ef version eg TanvirArjel.EFCore6.GenericRepository and TanvirArjel.EFCore5.GenericRepository etc

SimonCropp commented 3 years ago

i think this is a duplicate of https://github.com/dotnet/runtime/issues/53297

TanvirArjel commented 3 years ago

@SimonCropp The solution you have provided is not realistic anyway.

krwq commented 3 years ago

Is this a dup of https://github.com/dotnet/sdk/issues/18148 ?

TanvirArjel commented 3 years ago

@krwq Why it is in Milestone 7.0.0? Then how shall we update our packages to support v6.0.0. Currently, adding support for the .NET 6.0 in our NuGet packages does not work due to this blocking issue.

TanvirArjel commented 3 years ago

@krwq This is a blocking issue. Download this this repository and enable .NET 6.0 support and build. You will see the build failed.

TanvirArjel commented 3 years ago

@krwq

Is this a dup of dotnet/sdk#18148

Yes! Seems so.

safern commented 3 years ago

Closing this issue as a dup of: https://github.com/dotnet/sdk/issues/18148 which was fixed and the fix should be available on the Preview7 SDK.