Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

531
Visualizações
How to link UWP Class Library into an WPF Application?

How to link UWP Class Library into an WPF Application?

I have created an UWP Class Library with a single test class. I have an WPF .NET application which wants to consume that class library. What are the steps I need to follow?

Following this tutorial, I wanted to add library MyLib in my Application MyApp. But I am finding following compiler errors,

Severity Code Description Project File Line Suppression State Error NU1201 Project MyLib is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project MyLib supports: uap10.0.19041 (UAP,Version=v10.0.19041) MyApp C:\Users....\MyApp.csproj

##UPDATE

After adding following code,

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyLib\MyLib.csproj" />
  </ItemGroup>

</Project>

as suggested by TamBui in the answer, I am getting build error. However there have been two compiler warnings from the beginning. Sharing if it can give any clue,

  1. Warning NETSDK1137 It is no longer necessary to use the Microsoft.NET.Sdk.WindowsDesktop SDK. Consider changing the Sdk attribute of the root Project element to 'Microsoft.NET.Sdk'. MyApp C:\Program Files\dotnet\sdk\5.0.103\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets 376

  2. Warning MSB3270 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Users...\MyLib\bin\x64\Debug\MyLib.dll", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. MyApp C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2123

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You need to add the AssetTargetFallback that matches your UWP project's target version to your WPF project's PropertyGroup. Select your WPF project in the Solution Explorer, and you will be able to edit the project's properties.

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>netcoreapp3.1</TargetFramework>
  <RootNamespace>_68824006</RootNamespace>
  <AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
  <UseWPF>true</UseWPF>
</PropertyGroup>
over 4 years ago · Santiago Trujillo Relatório

0

A WPF application cannot reference a UWP class library. In short, the two different platforms or frameworks are not compatible with each other.

You should change the target framework of your class library (MyLib.csproj) to either .NET Standard or the same framework that your WPF app targets:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

</Project>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda