Why does paket include "When" conditions which check framework
Description
When paket sets contents in old sytle proj files it includes when conditions for all the different frameworks.
Why does this happen? - could it not check the targetting and then only add the relevant references?
Repro steps
Project targeting netstandard2.0 Add dependency Paket adds many references each within a "when" condition
Expected behavior
Only relevant references based on the target framework/frameworks
Actual behavior
All frameworks added
Known workarounds
Set restriction to "known" in use frameworks (but can still get many)
by default, since your paket.dependencies group has specified no limit to the frameworks you expect to support, paket will write out conditions for every TFM found in the various packages you're managing. if you add a set of framework restrictions, you should see this noise reduce quite a bit.
yeah, that's my workaround.
However, my question is...if i set restriction for say net471,netstandard2.0,net6-windows
Why does every project need that.
Can paket not check the TargetFrameworkVersion, TargetFramework, TargetFrameworks nodes to know which type to add.
Granted, this means if you change the framework, you need to do a fresh paket install (so maybe it should be behind a command line arg to enable).
That would reduce ALL noise in the project files :)
in that case, you could set framework: auto-detect as described here, right?
The main reason why paket wouldn't do those things is because as soon as you want to do those things, you have to do MSBuild evaluations. That's a large and fragile dependency to bring in.
in that case, you could set
framework: auto-detectas described here, right?
No, that still sets all the different dependencies for every target version. ☹️
The main reason why paket wouldn't do those things is because as soon as you want to do those things, you have to do MSBuild evaluations. That's a large and fragile dependency to bring in.
Whilst I do get your point. Having just added a new project targeting a new framework and every single one of my 200+ projects getting changes to add the extra (unused) dependencies is quite...unhelpful.
Having started to dig into this myself for my single use case. It got me thinking...paket is already doing this kind of logic as it's adding in the conditions for the choose.
Therefore the 3 items that are used in the conditions call all be calculated (with relative ease) and are defined in core msbuild targets which can't really change due to the fact that everyone's project files would become invalid if it was changed.
Therefore, I am unsure as to why paket cannot just add the required references for the target framework version (.net framework only) or or the target framework(s). It should be a case of reading the value of the node, and then calculating the values which the "when" conditions use. And if there is a match, add the reference. If no match, do not add it.
I've got a console application (C#) which I can share which I've setup on my repos to run after paket (via a batch file) which reads the proj files and removes invalid/not required "when" nodes. This is supporting net471, netstandard2.0 and net6.0-windows.