dotnet restore not using PackageReference condition

落花浮王杯 提交于 2021-02-09 09:21:06

问题


my project has multiple target frameworks, 2 of the package reference need to use a different version for .net461

when building in VS 2017 everything works and the dependency shows using the right versions.

but when build using dotnet cli, the dependency shows the wrong version is being use for .net461. is this a bug in dotnet cli?

I also try putting those 2 pkg in another ItemGroup tag with condition but still the same

update: for anyone else running in to this issue, I ended up using <Choose> with <when> condition to fix this.. so look something like this.

  <Choose>
<When Condition=" '$(TargetFramework)' == 'net461' ">
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="7.0.1" />
    <PackageReference Include="RestSharp" Version="105.2.3" />
  </ItemGroup>
</When>
<When Condition=" '$(TargetFramework)' == 'net451' ">
  <ItemGroup>
    <PackageReference Include="RestSharp" Version="105.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="7.0.1" />
  </ItemGroup>
</When>
<Otherwise>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
    <PackageReference Include="RestSharp" Version="106.2.1" />
  </ItemGroup>
</Otherwise>

来源:https://stackoverflow.com/questions/54485020/dotnet-restore-not-using-packagereference-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!