JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
563 stars 118 forks source link

Dependency Version Conflicts #257

Closed RyanThomas73 closed 3 years ago

RyanThomas73 commented 4 years ago

Lamar.Microsoft.DependencyInjection contains a package reference to Microsoft.AspNetCore.Hosting.Abstractions.

The latter is no longer published via nuget, the last published version being v2.2.0 which was publishes almost 2 years ago. See https://www.nuget.org/packages/Microsoft.AspNetCore.Hosting.Abstractions/. Newer versions beyond that (e.g v3.1.0) ship directly with the net core target framework.

Including this dependency creates version conflicts when used in applications targeting later net core runtimes. For example:

Encountered conflict between 'CopyLocal:<path>\.nuget\packages\microsoft.aspnetcore.hosting.abstractions\2.1.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll' and 'CopyLocal:<path>\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x64\3.1.5\runtimes\win-x64\lib\netcoreapp3.1\Microsoft.AspNetCore.Hosting.Abstractions.dll'.

The library should be switched to referencing the Microsoft.Extensions.Hosting.Abstractions package and/or multi targeting the different netcoreapp frameworks to ensure that the correct dependencies are used and that runtime signature differences do not occur.

jeremydmiller commented 3 years ago

The library as is is this:

  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
    <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="[2.1.0,4.0)" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="[2.1.0,4.0)" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="[2.1.0,4.0)" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
    <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="[2.1.0,4.0)" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="[3.0.0,4.0.0)" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="[3.0.0,4.0.0)" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="[3.0.0,4.0.0)" />
  </ItemGroup>

The assumption is that if you were targeting ASP.Net Core 3.1, then your library would use netstandard2.1.

I didn't want to cut off support for ASP.Net Core 2.* at the time (and probably still don't).

RyanThomas73 commented 3 years ago

The problem is the netstandard2.1 is referencing Microsoft.AspNetCore.Hosting.Abstractions which is discontinued / not supported for netstandard2.1. The netstandard2.1 version needs to reference Microsoft.Extensions.Hosting.Abstractions only (which only has abstractions for IHost(Builder) now not IWebHost(Builder)).

So that is one option. Target the correct extension library that does support netstandard2.1 and remove the extension methods targeting WebHostBuilder.

If you wish to maintain the extension methods targeting WebHostBuilder it will need to target netcoreapp3.

jeremydmiller commented 3 years ago

That's a good point about targeting the runtimes instead of netstandard**** for the adapter library. I can't ditch WebHostBuilder support though, that'd be screaming from different folks.

jeremydmiller commented 3 years ago

This should be addressed by Lamar v4.3.1