将ASP.Net Core集成到WPF应用程序中 [英] Integrate ASP.Net Core into an WPF application

查看:337
本文介绍了将ASP.Net Core集成到WPF应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将ASP.NET Core WebApi项目集成到WPF应用程序(最新的ASP.NET Core,最新的.NET Framework)中.这个想法是为用户提供一个REST API,以远程控制应用程序.但是,我无法将其集成到WPF应用程序中,并且一旦在WPF项目中引用Web项目,便会遇到编译错误:

I am currently trying to integrate an ASP.NET Core WebApi project into an WPF application (latest ASP.NET Core, latest .NET Framework). The idea is to provide a REST API for the user to control the application remotely. However, I was not able to integrate it into the WPF application and as soon as I reference the web project in the WPF project I am faced with a compilation error:

未知的构建错误,'无法解析对程序集'Microsoft.AspNetCore.Mvc.Core,版本= 2.1.2.0,Culture =中性PublicKeyToken = adb9793829ddae60的依赖关系,因为尚未预先加载它.在使用ReflectionOnly API时,依赖关系程序集必须通过ReflectionOnlyAssemblyResolve事件预先加载或按需加载."

"Unknown build error, 'Cannot resolve dependency to assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.2.0, Culture=neutral PublicKeyToken=adb9793829ddae60' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event."

有什么想法可以解决这个问题吗?

Any ideas how to solve that problem?

这是示例VS2017解决方案,其中包含WPF项目和ASP.NET Core项目,而我只是在WPF项目中添加了对ASP.NET Core项目的引用.

This is an example VS2017 solution that contains a WPF project and an ASP.NET Core project and I just added a reference to the ASP.NET Core project in the WPF project.

更新:将ASP.NET Core项目设置为面向整个.NET框架,并且未使用.NET Core.

UPDATE: The ASP.NET Core project is set up to target the full .NET framework and is not using .NET Core.

推荐答案

只是为了解决构建错误,您可以安装必需的缺少的Nuget包(WebApplication1的依赖项)及其依赖项.

Just to solve your build errors, you can install required missing Nuget packages (dependencies of WebApplication1) and their dependencies.

通过在WpfApp1上安装followinf Nuget软件包,我能够成功构建并运行您提供的项目:

I was able to successfully build and run your provided project by installing followinf Nuget packages on WpfApp1:

  1. Microsoft.AspNetCore.MVC.Core
  2. Microsoft.AspNetCore.Razor.Runtime

这篇关于将ASP.Net Core集成到WPF应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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