-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.ValueTuple and System.ComponentModel.Annotations #183
Comments
Hi @segor Both System.ComponentModel.Annotations and System.ValueTuple nuget packages indeed contain actual implementations inside them, but they are not used on any of the currently supported frameworks. The types in those nuget package are already part of the shared framework of the currently supported frameworks (.NET 8.0+, .NET Framework 4.6.2+). |
@carlossanlop Let me explain the reason of my question. We do not reference these packages directly in our multitargeted project (.net 4.8 and .net 8), but they are transitive packages and the corresponding assemblies are being copied to the output binaries folder. According to our security compliance all the distributed open source libraries have to be tracked including their license, authors , repository, etc. The code repository has to be up to date and maintained. As for me, these requirements are reasonable.
Do I understand correctly that these assemblies can be excluded from distribution and the app will work without them? It looks like the libraries contain the type forwarding instructions. If so,.where are these instructions located? Thanks |
In both cases the framework contains the assembly. On NET 4.8 the assembly is part of .NETFramework and loaded from the GAC ( You can see this if you try to run the following: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net4.8;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project> program.cs using System;
using System.Reflection;
Console.WriteLine(Assembly.Load("System.ValueTuple").Location);
Console.WriteLine(Type.GetType("System.ValueTuple, System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51").Assembly.Location); Output
|
@ericstj thanks for the response and the code snippet. Yes, for the net4.8 it looks like the assemblies So I think the issue can be closed but I would add that placing these unnecessary(?) assemblies into the output folder may confuse developers and it would be interesting to know why it happens. PS <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net4.8;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <!--remove the unnecessary assemblies-->
<Exec Command="del /s System.ValueTuple.dll System.ComponentModel.Annotations.dll" />
</Target>
</Project>
using System;
Console.WriteLine(typeof(System.ValueTuple).Assembly.Location);
Console.WriteLine(typeof(System.ComponentModel.DataAnnotations.DataTypeAttribute).Assembly.Location); Output for net4.8:
Output for net8.0:
|
You can avoid a target by using
They won't be copied on .NET 6+. On .NETFramework the files are copied because the packages have newer versions than the assemblies from the NET4.8 targeting pack, so they don't get dropped, however their assembly versions are still within the range that's unified by the framework's loader, so they are ignored at runtime in favor of the framework copy. Here's the relevant snippet from the build log:
We could ship new copies of these packages, just to make it so that they aren't copied on .NETFramework versions, but we'd prefer folks just stop using the packages altogether since the types are built into the framework and the packages aren't required. |
Fwiw .NET 4.6.2 is still supported and doesn't have inbox System.ValueTuple. |
@ericstj
This option works well if I use it for
To reproduce it just add
The problem is that these libraries come mostly from other .NET Runtime libraries . For example, in my project,
So question is what is better, to request folks just stop using the unnecessary packages in Microsoft.Bcl.TimeProvider (v8.0.0) and System.Text.Json (v8.0.5) and in other .NET runtime libraries or just to release a new version of System.ValueTuple. |
To use types from
But it does seem to do that. I think that's a NuGet bug. I filed NuGet/Home#13951
That's a very good point. We do still need the reference on .NET 4.6.2 for these libraries, there's no alternative. We could have them multi-target their .NETFramework targets to drop the package on 4.7 and later. @ViktorHofer what are your thoughts on this? |
Certainly possible but Microsoft.Bcl.* aren't the only packages that transitively bring System.ValueTuple in. I see multiple hits just in the dotnet/runtime repo: https://github.com/search?q=repo%3Adotnet%2Fruntime%20%3CPackageReference%20Include%3D%22System.ValueTuple%22&type=code Given that .NET Framework 4.6.2 is still in-support and doesn't have System.ValueTuple inbox, I would prefer to add the library to this repository. |
What's home repository for System.ValueTuple and System.ComponentModel.Annotations?
Can you please consider to migrate them into the repository?
Thanks!
The text was updated successfully, but these errors were encountered: