.Net core 3: manually adding framework dependencies

chr*_*dot 8 wpf .net-core asp.net-core

Since the release of version 3.0, it is now possible to write WPF applications in .net core, and this is really nice!

On the other hand, on .net core, the dependency system now relies on full framework and no more and multiple nuget dependencies. This is not a problem until you want to mix for instance WPF and ASP.net core in the same application (I have a case where I want a UI with a webserver handling websockets endpoints).

When I create an ASP.Net core project using VS2019, I get these frameworks dependencies (in solution explorer, on the assembly Dependencies/Frameworks node):

  • Microsoft.AspNetCore.App
  • Microsoft.NETCore.App

On the other side when I create a core 3 WPF project, I get the following framework dependencies:

  • Microsoft.NETCore.App
  • Microsoft.WindowsDesktop.App.Ref

What I would like to get as dependencies would be teh following:

  • Microsoft.AspNetCore.App
  • Microsoft.NETCore.App
  • Microsoft.WindowsDesktop.App.Ref

How can I manually add the Microsoft.NETCore.App into the WPF application (or in the other way round)? There's nothing in the csproj about that...

In the csproj of the asp.net core I get that:

<PropertyGroup>
  <TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

And in the WPF application, I get that:

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>netcoreapp3.0</TargetFramework>
  <UseWPF>true</UseWPF>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

Is there any trick?

chr*_*dot 14

好的,我发现了(感谢安德鲁!):

只需在 csproj 中添加该部分:

<ItemGroup>
  <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

所以在我的例子中,我只需要将它添加到我的 WPF 项目中。

诀窍是该项目不是同一类型。对于我们拥有的 WPF 之一:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
Run Code Online (Sandbox Code Playgroud)

而对于 ASP.NET Core 我们有:

<Project Sdk="Microsoft.NET.Sdk.Web">
Run Code Online (Sandbox Code Playgroud)

后面的这个会自动嵌入 Microsoft.AspNetCore.App 引用,而 WPF 没有。

  • 非常感谢您,您的帖子刚刚结束了一个小时的关于如何将 System.Windows.Data 使用到我的 .NET core 3.1 类库中的研究。添加框架依赖项似乎是每个人都假设任何人都已经知道的事情之一...... (2认同)