.Net core 3:手动添加框架依赖 [英] .Net core 3: manually adding framework dependencies

查看:138
本文介绍了.Net core 3:手动添加框架依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自3.0版本发布以来,现在可以在.net core中编写WPF应用程序了,这真是太好了!

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

另一方面,在 .net core 上,依赖系统现在依赖于完整的框架,不再有多个 nuget 依赖.这不是问题,除非您想在同一个应用程序中混合使用 WPF 和 ASP.net 核心(我有一个案例,我想要一个带有处理 websockets 端点的网络服务器的 UI).

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).

当我使用 VS2019 创建 ASP.Net 核心项目时,我获得了这些框架依赖项(在解决方案资源管理器中,在程序集依赖项/框架节点上):

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

另一方面,当我创建一个核心 3 WPF 项目时,我得到以下框架依赖项:

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

如何手动将 Microsoft.NETCore.App 添加到 WPF 应用程序中(或以其他方式)?csproj 中没有任何内容...

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...

在 asp.net 核心的 csproj 中,我明白了:

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

<PropertyGroup>
  <TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

在 WPF 应用程序中,我明白了:

And in the WPF application, I get that:

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>netcoreapp3.0</TargetFramework>
  <UseWPF>true</UseWPF>
</PropertyGroup>

有什么技巧吗?

推荐答案

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

OK, I found it out (thanks Andrew!):

只需在 csproj 中添加该部分:

Just add that section in the csproj:

<ItemGroup>
  <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

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

So in my example I just had to add that into my WPF project.

诀窍在于该项目的类型不同.对于我们拥有的 WPF:

The trick was that the project was not of the same type. Fo the WPF one we had:

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

而对于我们拥有的 asp.net 核心:

Whereas for the asp.net core one we had:

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

后一个会自动嵌入 Microsoft.AspNetCore.App 引用,而 WPF 不会.

This later one automatically embedds the Microsoft.AspNetCore.App reference, and the WPF one does not.

这篇关于.Net core 3:手动添加框架依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆