简体   繁体   中英

Nuget Spec AspNet vs AspNetCore

I am creating a library that I want to have different behaviour based on the type of project that is dependent on it.

Here are the 3 types of projects I want to separate:

  • AspNet (.NET Framework)
  • AspNetCore 2.1
  • AspNetCore 3.1

Here is my csproj :

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
  <PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
  <PackageReference Include="System.Net.Http" Version="4.3.4" />

  <Content Remove="NetCore\**" />
  <Compile Remove="NetCore\**" />
  <EmbeddedResource Remove="NetCore\**" />
  <None Remove="NetCore\**" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
  <PackageReference Include="Microsoft.AspNetCore.All" />
  <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" />

  <Content Remove="NetFramework\**" />
  <Compile Remove="NetFramework\**" />
  <EmbeddedResource Remove="NetFramework\**" />
  <None Remove="NetFramework\**" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
  <FrameworkReference Include="Microsoft.AspNetCore.App" />

  <Content Remove="NetFramework\**" />
  <Compile Remove="NetFramework\**" />
  <EmbeddedResource Remove="NetFramework\**" />
  <None Remove="NetFramework\**" />
</ItemGroup>

As you can see, I have conditional builds for each of the platforms that I want to target.

  • For normal apps and ASP.NET we have '$(TargetFramework)' == 'netstandard2.0'
  • For ASP.NET Core 2.1 we have '$(TargetFramework)' == 'netcoreapp2.1'
  • For ASP.NET Core 3.1 we have '$(TargetFramework)' == 'netcoreapp3.1'

Here are my dependencies in nuspec :

<dependencies>
    <group targetFramework="netstandard2.0">
        <dependency id="TweetinviAPI" version="5.0.0" />
        <dependency id="Microsoft.AspNetCore.WebUtilities" version="2.2.0" />
        <dependency id="System.Net.Http" version="4.3.4" />
    </group>
    <group targetFramework=" netcoreapp2.1">
        <dependency id="TweetinviAPI" version="5.0.0" />
        <dependency id="Microsoft.AspNetCore.All" />
        <dependency id="Microsoft.AspNetCore.Http.Abstractions" version="2.1.1" />
    </group>
    <group targetFramework="netcoreapp3.1">
        <dependency id="TweetinviAPI" version="5.0.0" />
        <dependency id="Microsoft.AspNetCore.App" />
    </group>
</dependencies>

When adding the nuget package to any of the projects, I receive the following error:

  • ASPNetCore 2.1
TweetinviAPI.AspNet 5.0.0 does not provide an inclusive lower bound for dependency Microsoft.AspNetCore.App. An approximate best match of Microsoft.AspNetCore.App 2.1.0 was resolved.  WebApplication

TweetinviAPI.AspNet 5.0.0 does not provide an inclusive lower bound for dependency Microsoft.AspNetCore.All. An approximate best match of Microsoft.AspNetCore.All 2.0.0 was resolved.  WebApplication-2.1
  • ASPNetCore 3.1
TweetinviAPI.AspNet 5.0.0 does not provide an inclusive lower bound for dependency Microsoft.AspNetCore.App. An approximate best match of Microsoft.AspNetCore.App 2.1.0 was resolved.  

This version of Microsoft.AspNetCore.App is only compatible with the netcoreapp2.1 target framework. Please target netcoreapp2.1 or choose a version of Microsoft.AspNetCore.App compatible with netcoreapp3.1.

Project is not working, any idea to make this work?

Thanks, Linvi

For anyone interested, this is what I ended up doing.

<dependencies>
    <group targetFramework="netstandard2.0">
        <dependency id="TweetinviAPI" version="5.0.0" />
        <dependency id="Microsoft.AspNetCore.WebUtilities" version="2.2.0" />
        <dependency id="System.Net.Http" version="4.3.4" />
    </group>
    <group targetFramework="netcoreapp2.1">
        <dependency id="TweetinviAPI" version="5.0.0" />
        <dependency id="Microsoft.AspNetCore.Http" version="2.1" />
        <dependency id="Microsoft.AspNetCore.Http.Abstractions" version="2.1" />
        <dependency id="Microsoft.Extensions.Options" version="2.1" />
    </group>
    <group targetFramework="netcoreapp3.1">
        <dependency id="TweetinviAPI" version="5.0.0" />
    </group>
</dependencies>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM