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

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

问题描述

自版本3.0发行以来,现在可以在.net核心中编写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核心上,依赖项系统现在依赖于完整的框架,不再依赖多个nuget依赖项.直到您要在同一应用程序中混合使用WPF和ASP.net核心(这是我要使用带有处理websockets终结点的Web服务器的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核心项目时,我得到了这些框架依赖项(在解决方案资源管理器中,在程序集Dependencies/Frameworks节点上):

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天全站免登陆