What is the intended way to target a specific version of the .NET Runtime?

Copper Contributor

I'm curious what is the intended way of targeting a specific version of the .NET runtime. As far as I can tell the runtime version required to run a .NET application has to be greater or equal to the version of the .NET SDK which built the application.

 

Example:

If I build a net6.0-window Forms project using .NET SDK 6.0.202 then the dll will have references to "System.Windows.Forms (6.0.2)" making it unable to run (or be built as a referenced package) by an older version.

 

The way to solve this seems to either be to force the .NET SDK version via global.json, or add FrameworkReference attributes for each of the referenced dlls. Neither of these seem to work well.

 

Adding a global.json which prohibits rollForward doesn't work well since the installed version of the SDK changes all the time. E.g. if I install .NET SDK 6.0.100 (which corresponds to 6.0.0 runtime) it will eventually be updated by Windows to some newer or patched version like 6.0.100-rc.1.21458.32 or 6.0.104. This breaks builds since these are not compatible with the global.json.

 

It is also very unclear how the .NET SDK version corresponds to the runtime version used. E.g. .NET SDK 6.0.202 (and 6.0.104) installs the 6.0.4 runtime. This means that I can't set rollForward to "patch" since that may result in a newer runtime. As far I can tell there is no way to look at the SDK version and know what runtime version I will get.

 

Using FrameworkReference is poorly documented and seems to require that each referenced runtime dll is explicitly added.

 

Since .NET is backwards compatible within MAJOR version I want to target the lowest possible runtime, and then allow the person running my application to select whichever is the most appropriate runtime for them. I also don't want to force projects which depend on my package to use a newer SDK version than what is necessary.

 

How is this problem meant to be solved?

0 Replies