adoconnection / RazorEngineCore

.NET6 Razor Template Engine
MIT License
582 stars 86 forks source link

NU1107 - Version conflict detected for Microsoft.CodeAnalysis.CSharp. #147

Open tohidazizi opened 1 month ago

tohidazizi commented 1 month ago

In my solution, the RazorEngineCore package is installed on a project referenced by a Web API project.

I get this error:

NU1107 Version conflict detected for Microsoft.CodeAnalysis.CSharp. Install/reference Microsoft.CodeAnalysis.CSharp 4.8.0 directly to project ICD.ChronicKidneyDisease.Api to resolve this issue. MySolution.Api -> MySolution.HtmlGeneratorAdapter -> RazorEngineCore 2024.4.1 -> Microsoft.CodeAnalysis.CSharp (>= 4.8.0) MySolution.Api -> Microsoft.VisualStudio.Web.CodeGeneration.Design 8.0.0 -> Microsoft.DotNet.Scaffolding.Shared 8.0.0 -> Microsoft.CodeAnalysis.CSharp.Features 4.8.0-3.final -> Microsoft.CodeAnalysis.CSharp (= 4.8.0-3.final).

I added the following line to the API project file but still got the above error.

<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />

Any idea how to fix it?

adoconnection commented 1 month ago

Hi, as a quick thought, I bet it has something to do with dependentAssembly. One of your project reference newer (or older) version of Microsoft.CodeAnalysis.CSharp

checklist:

usually this kind of runtime / assemblyBinding helps (this one is copy-paste from google with wrong version numbers)

<dependentAssembly>
    <assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-9.9.9.9" newVersion="1.0.0.0" />
</dependentAssembly>
leandro-almeida commented 1 month ago

Hi, i am also facing this issue:

Severity Code Description Project File Line Suppression State Error (active) NU1107 Version conflict detected for Microsoft.CodeAnalysis.CSharp. Install/reference Microsoft.CodeAnalysis.CSharp 4.8.0 directly to project TJPA.PagamentoPrecatorios.API to resolve this issue. TJPA.PagamentoPrecatorios.API -> TJPA.PagamentoPrecatorios.Infrastructure.Reporting -> RazorEngineCore 2024.4.1 -> Microsoft.CodeAnalysis.CSharp (>= 4.8.0) TJPA.PagamentoPrecatorios.API -> Microsoft.EntityFrameworkCore.Design 8.0.8 -> Microsoft.CodeAnalysis.CSharp.Workspaces 4.5.0 -> Microsoft.CodeAnalysis.CSharp (= 4.5.0). TJPA.PagamentoPrecatorios.API D:\TJPA\precatorios\api-pagamento-precatorios\src\TJPA.PagamentoPrecatorios.API\TJPA.PagamentoPrecatorios.API.csproj 1

After installing the recommended package <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" /> i still had the erros. So i looked out in my assemblies deps:

image

So i installed <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />, and removed <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" /> and got it to work.