Is it possible to use WPF within an .NET Standard Class Library or is this to be reserved for .NET Core? If so, is it possible to setup a .NET Core Class Library that uses WPF or does it necessarily have to be a .NET Core App?
-
Yes, but only on Windows: devblogs.microsoft.com/dotnet/…Isma– Isma2019-08-16 18:45:15 +00:00Commented Aug 16, 2019 at 18:45
-
1But isn't the blog talking about a .NET Core App rather than a plain Class Library?mu88– mu882019-08-16 20:41:03 +00:00Commented Aug 16, 2019 at 20:41
-
WPF is not part of .NET Standard, so if your class library strictly targets netstandardx.x, please don't use WPF.Lex Li– Lex Li2019-08-16 20:52:57 +00:00Commented Aug 16, 2019 at 20:52
-
And what about a NET Core Class Library? Would that work or only a NET Core Application?mu88– mu882019-08-16 20:54:29 +00:00Commented Aug 16, 2019 at 20:54
-
WPF project can reference and consume .NET Standard libraries. Full .NET Framework version is a superset of .NET Standard.Fabio– Fabio2019-08-16 23:01:14 +00:00Commented Aug 16, 2019 at 23:01
|
Show 2 more comments
1 Answer
Finally, I got in contact with Microsoft. They were very helpful and provided the following snippet of a *.csproj file to me:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
With this, I get a .NET Core class library including WPF. Additionally, I had to remove App.xaml and App.cs. This was necessary since those contain <Application> tags in XAML which aren’t allowed in WPF libraries.