Multi-target project won't load the right packages

Shimmy Weitzhandler 291 Reputation points
2020-10-05T22:30:35.68+00:00

Hi,

I have a multi-targeting project with the following csproj content:

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

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore">
      <Version Condition="'$(TargetFramework)' == 'netstandard2.0'">Version="[2.*,5.*)"</Version>
      <Version Condition="'$(TargetFramework)' == 'netstandard2.1'">5.*</Version>
    </PackageReference>
  </ItemGroup>
</Project>

Interestingly, the EF Core 2.0 package is referenced to the .NET Standard 2.1 target too - whereas I'd want it to reference the 5+ version.
I've also tried replacing 5.* with 5.0.0-rc.1.20451.13, which didn't make any difference.

Thank you

Community Center | Not monitored
0 comments No comments
{count} votes

Accepted answer
  1. Shimmy Weitzhandler 291 Reputation points
    2020-10-07T08:46:26.92+00:00

    For some reason, specifying the exact version seems to be working now. This might be because I now installed preview version of VS which supports .NET 5 RC.
    This code worked:

    xml
    <ItemGroup>
      <PackageReference Include="Microsoft.EntityFrameworkCore">
        <Version Condition="'$(TargetFramework)' == 'netstandard2.0'">[2.0.0,5.0.0)</Version>
        <Version Condition="'$(TargetFramework)' == 'netstandard2.1'">5.0.0-rc.1.20451.13</Version>
      </PackageReference>
    </ItemGroup>
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,426 Reputation points
    2020-10-06T08:15:40.907+00:00

    Hi shimmy,

    You could have a try to use different ItemGroups to specify nuget package:

      <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
          <PackageReference Include="Microsoft.EntityFrameworkCore">
              <Version>[2.*,5.*)</Version>
          </PackageReference>
      </ItemGroup>
    
      <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
          <PackageReference Include="Microsoft.EntityFrameworkCore">
            <Version>5.*</Version>
          </PackageReference>
      </ItemGroup>
    

    Best Regards,
    Dylan


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.