4

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?

7
  • Yes, but only on Windows: devblogs.microsoft.com/dotnet/… Commented Aug 16, 2019 at 18:45
  • 1
    But isn't the blog talking about a .NET Core App rather than a plain Class Library? Commented 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. Commented Aug 16, 2019 at 20:52
  • And what about a NET Core Class Library? Would that work or only a NET Core Application? Commented 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. Commented Aug 16, 2019 at 23:01

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.