RickStrahl / Westwind.Scripting

Small C# library to provide dynamic runtime code compilation from source code for code and expressions execution
205 stars 43 forks source link

Conflict with Microsoft.CodeAnalysis.Common and Microsoft.EntityFrameworkCore.Tools 8.0.0 #26

Open xantari opened 10 months ago

xantari commented 10 months ago

@RickStrahl Here is a similar issue to #18

Severity    Code    Description Project File    Line    Suppression State
Error   NU1107  Version conflict detected for Microsoft.CodeAnalysis.Common. Install/reference Microsoft.CodeAnalysis.Common 4.6.0 directly to project OPG.VIIC.Web.Core to resolve this issue. 
 OPG.VIIC.Web.Core -> Westwind.Scripting 1.3.3 -> Microsoft.CodeAnalysis.Scripting.Common 4.6.0 -> Microsoft.CodeAnalysis.Common (= 4.6.0) 
 OPG.VIIC.Web.Core -> Microsoft.EntityFrameworkCore.Tools 8.0.0 -> Microsoft.EntityFrameworkCore.Design 8.0.0 -> Microsoft.CodeAnalysis.CSharp.Workspaces 4.5.0 -> Microsoft.CodeAnalysis.Common (= 4.5.0). OPG.VIIC.Web.Core   C:\TFS\Intranet\OPG.VIIC.Web.Core\OPG.VIIC.Web.Core.csproj  1   

Trying to upgrade to .NET Core 8.0 and the corresponding EF packages. There is a conflict now with Microsoft.EntityFrameworkCore.Tools 8.0.0 which uses Microsoft.CodeAnalysis.Common 4.5.0, but your package uses Microsoft.CodeAnalysis.Scripting.Common 4.6.0.

I kinda wonder if separate build profiles for different versions of .NET would fix this? For instance if you are targeting .NET Core 8.0, then the assumption being is you would use .NET 8.0 packages for things like Microsoft.EntityFrameworkCore.Tools which seem to use Microsoft.CodeAnalysis.Common 4.5.0 (instead of the later 4.6.0)?

In legacy .NET framework, we had this mapping functionality you could do in the web.config:

      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>
      </dependentAssembly>

In the above example it would cast any references from Antlr3.Runtime from versions 0.0.0.0 to 3.5.0.2 to 3.5.0.2 assembly version.

I tried adding this to my .NET 8.0 application .csproj, but it didn't help:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
xantari commented 10 months ago

One more thought. Create multiple types of nuget publishes.

Westwind.Scripting - Codeanalysis 4.5.0 (Targets Code analysis 4.5.0) Westwind.Scripting - Codeanalysis 4.6.0 (Targets Code analysis 4.6.0)

Etc...

Then you import the appropriate type of nuget package that complies with the version of the Microsoft.CodeAnalysis.CSharp version you are bound to in the project?

Alternatively, you could downgrade to 4.5.0 and mark your project as being compatible with Microsoft.CodeAnalysis.CSharp >= 4.5.0 so it works with 4.5.0 and 4.6.0 ? (I figure this might be easier then asking Microsoft to add the >= Microsoft.CodeAnalysis.CSharp criteria to their package?)

xantari commented 10 months ago

More comments, this might be resolvable by manually creating .nuspec files instead of the built in dotnet pack features: https://github.com/NuGet/Home/issues/11842

Morrison76 commented 8 months ago

I have a similar problem. Couldn't update Microsoft.EntityFrameworkCore.Design to 8.0.0 version. @RickStrahl could you please check this issue and optimize a good library to use it in .net 8? Thanks!

@xantari I have downgraded Westwind.Scripting to 1.2.7 version, and there fixed is the problem