C#C
C#6mo ago
24 replies
zed

System.ValueTuple 4.6.1 in a .NET Framework 4.8 app inserts strange sections into .csproj

Typically, a NuGet package update just increases the version specified in the project file. One of the attached screenshots shows an example of what it looks like to update System.Runtime.CompilerServices.Unsafe from version 6.1.0 to 6.1.2.

However, doing the same for System.ValueTuple (in this case, from 4.5.0 to 4.6.1) removes the corresponding <Reference> tag entirely (screenshot of the diff attached). Additionally, it adds an <Import> tag for a .targets file in the NuGet packages folder (as well as a potential error message, if that file is missing):
  <Import Project="..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets" Condition="Exists('..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets'))" />
  </Target>

That file itself just has this content, and nothing else:
<Project>

  <!-- System.ValueTuple is inbox on .NET Framework >= 4.7.1 and therefore any potential redirect for it should be removed.
       This is necessary as the assembly version in the already shipped packages is higher than what's provided inbox on .NET Framework. -->
  <Target Name="RemoveValueTupleRedirectForNet471AndAbove" DependsOnTargets="ResolveAssemblyReferences" BeforeTargets="GenerateBindingRedirects">
    <ItemGroup>
      <SuggestedBindingRedirects Remove="System.ValueTuple, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
    </ItemGroup>
  </Target>

</Project>


It did that for every project that referenced System.ValueTuple. Since the app still starts up, this is not an urgent issue, but it feels strange committing that code, since I don't understand it. This is the first time I'm seeing anything like that, and we've updated our packages many times before. Is this normal? Is this a new mechanism to add packages? Where is the package actually referenced now? I'm on VS 17.14.8.
image.png
image.png
Was this page helpful?