-
I have a number of open-source libraries that use Multi-targeting to create a single package for multiple targets. I'm now updating these libraries to add support for WinUI and under typical circumstances the standard approach using TFMs, conditional 'PropertyGroup' and 'ItemGroup' entries works fine. However, on one of my projects we are using WPF, .NET 6 and need to use the Windows Runtime API. In order to do this you have to set an explictly versioned TFM, e.g net6.0-windows10.0.18362.0. This now causes a conflict with WinUI as the TFM is also an explict version e.g. net6.0-windows10.0.18362.0. Firstly there isn't a way of specifing a different library for WPF and WinUI for the same TFM and if i include both 'UseWPF' and 'UseWinUI' that it will include framework references that are not needed. Even if I include a net6.0-windows7.0 the net6.0-windows10.0.18362.0 version is installed instead, adding the WinUI packages unnecessaily. The only option i have it to create a seperate project, which loses a lot of the benefits of multi-targeting in the first place. Any ideas how to work roung this problem? This is an example of the frameworks definition.
And the PropertyGroup and ItemGroup
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If the only thing you want is for NuGet to not force the consuming project to add Again, if this is all you want, you can work around this by not using a NuGet generated nuspec, but having one you maintain yourself, docs here on how to pack with your own nuspec. Another idea is to have a build/pack script that runs If, however, you want to have different APIs for WinUI and WPF, then that's something that NuGet doesn't support as NuGet's only "pivot point", for automatic asset selection, is target framework. Therefore, if both your WPF and WinUI code use the same "NuGet Target Framework", then NuGet doesn't have the capability to do different things. I see one option as creating separate packages. You mentioned using different projects, that's probably the best way. Also you could move common code into a third project/package if you're concerned about code duplication across two projects. But you could also get by with a single project using multiple "configurations", one of which is for WPF, the other WinUI, but this means that your build scripts will need to restore and build the project/solution twice, once for each configuration. You could also create an issue in https://github.com/dotnet/sdk asking them to work with the NuGet team (and WPF/WinUI teams?) to design a solution that can allow WPF and WinUI libraries, without adding unnecessary framework references. But you might want to pre-emptively justify why having two different packages with WPF/WinUI specific code, and a third with shared common code used by the other others, is not a suitable solution. Spending time implementing features with workarounds means we won't have time to work on other new features, so understanding the impact helps us prioritize more effectively. Another option is to use NuGet only as a MSBuild extensibility point. Don't let NuGet put your assemblies under
You can consider using |
Beta Was this translation helpful? Give feedback.
If the only thing you want is for NuGet to not force the consuming project to add
<FrameworkReference ... />
, with the knowledge that when the consuming project is using WPF or WinUI, that the project will have it anyway, then I suggest creating a Feature Request, asking for a pack to use aSupressFrameworkReferences
property, or similar, to work similar to how SuppressDependenciesWhenPacking and IncludeBuildOutput work. Note, this still means that you'll have a single assembly per uniqu…