Paket icon indicating copy to clipboard operation
Paket copied to clipboard

Why does paket include "When" conditions which check framework

Open BlythMeister opened this issue 3 years ago • 7 comments

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)

BlythMeister avatar Mar 18 '22 16:03 BlythMeister

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.

baronfel avatar Mar 18 '22 16:03 baronfel

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 :)

BlythMeister avatar Mar 18 '22 16:03 BlythMeister

in that case, you could set framework: auto-detect as described here, right?

baronfel avatar Mar 18 '22 17:03 baronfel

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.

baronfel avatar Mar 18 '22 17:03 baronfel

in that case, you could set framework: auto-detect as described here, right?

No, that still sets all the different dependencies for every target version. ☹️

BlythMeister avatar Mar 18 '22 18:03 BlythMeister

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.

BlythMeister avatar Mar 18 '22 18:03 BlythMeister

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.

Program.txt

BlythMeister avatar Mar 23 '22 21:03 BlythMeister