-1

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 :

  1. Has reference Microsoft.Windows.SDK.Contracts version 10.0.22621.2428 nuget package
  2. Has a function that calls Windows.ApplicationModel.Package.Current;
  3. public string LibraryFunctionToGetPackageName() { ... }
  4. Assume it has other functions related to Store API

xWpfApp1 : WPF with .NET Framework 4.8

  1. References ClassLibrarydotnetStandard2
  2. Calls function : var s = c.LibraryFunctionToGetPackageName();
  3. (Do not run xWpfApp1 directly, instead run xWpfApp1_Package.)

xWpfApp1_Package : Packaging project for xWpfApp1

  1. Compile and Run.
  2. Click on button #1 to call library function
  3. You should see, it does succeed.

WpfAppdotnet8 : WPF with .NET Core 8.0

  1. References ClassLibrarydotnetStandard2
  2. Calls function: this.Title = c.LibraryFunctionToGetPackageName();
  3. (Same, do not run WpfAppdotnet8 directly, instead run below packaging project.)

WPFdotnet8_PackageToPublishToStore : Packaging project for WpfAppdotnet8

  1. Compile and Run the package project
  2. Click on button #1
  3. You will see Error during library call. Exception: "System.PlatformNotSupportedException"

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.

4
  • Why don't you just get rid of .NET standard, keep 4.8 (or move it to .NET 8) and .NET 8 together devblogs.microsoft.com/dotnet/the-future-of-net-standard Commented May 9, 2024 at 16:34
  • 2
    You have already posted the same question stackoverflow.com/q/78450352/3137337 by different account. Perhaps you no longer need to keep the previous question? Commented May 10, 2024 at 0:38
  • @SimonMourier We have lots of code in library which is currently in use by WPF and UWP apps. migrating library may break old apps. Commented May 10, 2024 at 9:42
  • No it shouldn't break many things. Have you tried to replace it by .NET Framework 4.8 or .NET 8? Code should be very compatible in this direction since .NET standard is just a list of contracts, an (now outdated, was always made for transition) abstract intersection of real platforms. Commented May 10, 2024 at 10:48

1 Answer 1

2

.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>
Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely astounding, @mm8 Sir! Your solution worked like a dream! Thank you immensely!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.