Hi fellow MSFT developers,
I have created a sample project for your convenience, available at
https://github.com/JiyaDesai-FandCo/WpfAppdotnet8
We have existing code in Library (of type .NET Standard 2.0) that heavily uses Store APIs, Addon and stuff. and we reuse this library in all our Store App projects. Currently this library is used in WPF (.NET 4.8) and UWP projects and all is running fine.
Problem occurred when we decided to create WPF project with .NET Core 8.0 That's where we are unable to use the library.
Now let me explain the sample project on github, which you can download, explore and help us to identify issue or workaround. The aim is to reuse library in all kind of projects. (WPF with .NET 4.8, UWP and WPF with .NET Core 8.0 ). Keeping in mind we are going to publish it on Store.
Also Note: while you debug, please always run packaging projects only.
ClassLibrarydotnetStandard2 :
xWpfApp1 : WPF with .NET Framework 4.8
xWpfApp1_Package : Packaging project for xWpfApp1
WpfAppdotnet8 : WPF with .NET Core 8.0
WPFdotnet8_PackageToPublishToStore : Packaging project for WpfAppdotnet8
We want to resolve this error, so that we can use library successfully in WpfAppdotnet8
Hope I was able to explain.
Thanks & Regards
Awaiting your response very curiously.
.NET 6 and later use the target framework moniker option to consume Windows Runtime APIs:
Call Windows Runtime APIs in desktop apps
This means that you should build multiple versions of your class library:
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0-windows10.0.17763.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Condition="'$(TargetFramework)' == 'netstandard2.0'"
Include="Microsoft.Windows.SDK.Contracts" Version="10.0.22621.3233">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
You should also include the OS version in the TFM in the .NET 8 project:
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>