简体   繁体   English

项目中的 Microsoft.AspNetCore.Mvc 引用导致 Blazor WASM 问题

[英]Microsoft.AspNetCore.Mvc Reference In Project Causes Blazor WASM Issues

I am trying to start a Blazor WASM application;我正在尝试启动 Blazor WASM 应用程序; I have the latest .NET 5 installed, VS2019 16.8, etc. I have existing projects that will be referenced in the both of the Blazor generated projects *.Client && *.Server.我安装了最新的 .NET 5、VS2019 16.8 等。我现有的项目将在 Blazor 生成的项目 *.Client && *.Server 中引用。 The .Server project handles the project references without issue. .Server 项目可以毫无问题地处理项目引用。 But, the .Client project is having issues with my "Library" project.但是,.Client 项目与我的“库”项目有问题。 When I add the project reference, I am getting these build errors:当我添加项目引用时,我收到这些构建错误:

The type or namespace name 'ApplicationPartAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?)命名空间“Microsoft.AspNetCore.Mvc.ApplicationParts”中不存在类型或命名空间名称“ApplicationPartAttribute”(您是否缺少程序集引用?)

I've since gone nearly file by file, class by class, in that project to narrow down the issue: name reference and usage of Microsoft.AspNetCore.Mvc will cause this build error.从那以后,我几乎逐个文件,逐个类地在该项目中缩小问题范围:Microsoft.AspNetCore.Mvc 的名称引用和使用将导致此构建错误。 Excluding these files or methods and then rebuilding the .Client project, solves the issue.排除这些文件或方法,然后重建 .Client 项目,即可解决问题。 The classes utilizing the .Mvc namespace all deal with my exception filters, action filters, etc and are rather vital to speedy development.使用 .Mvc 命名空间的类都处理我的异常过滤器、动作过滤器等​​,对于快速开发非常重要。 I'm leaning towards breaking up the library and having the .Mvc stuff reside separately, but, that seems rather ridiculous, but, then again, maybe I'm wrong.我倾向于拆分库并将 .Mvc 的东西分开存放,但是,这似乎很荒谬,但是,话说回来,也许我错了。

I've installed the Microsoft.AspNetCore.Mvc and Microsoft.AspNetCore.Mvc.Core nuget packages on the .Client project, and no change.我已经在 .Client 项目上安装了 Microsoft.AspNetCore.Mvc 和 Microsoft.AspNetCore.Mvc.Core nuget 包,没有任何变化。 All projects in the solution are running on .NET 5. These links speak about the issue and a sort of "fix" for it:解决方案中的所有项目都在 .NET 5 上运行。这些链接讨论了这个问题和一种“修复”:

When I was using the 16.8 Preview, I implemented this "fix", but debugging the Blazor project was a nightmare.当我使用 16.8 Preview 时,我实现了这个“修复”,但调试 Blazor 项目是一场噩梦。 Oddly, I've not found much info regarding this issue and why it is happening nor any true ways to fix it.奇怪的是,我没有找到太多关于这个问题的信息以及它为什么会发生,也没有找到任何真正的方法来解决它。

Has anyone encountered this issue?有没有人遇到过这个问题? Am I missing something here?我在这里错过了什么吗?

It's hard to say what exactly is happening or why from the above description.从上面的描述中很难说到底发生了什么或为什么会发生。 In my experience, when starting a new project, I will start with s working sample, and then slowly add my existing files or projects bit by bit and ensure that it continues to build and run as I go along.根据我的经验,当开始一个新项目时,我会从 s 个工作示例开始,然后一点一点地慢慢添加我现有的文件或项目,并确保它随着我的进行而继续构建和运行。 Then as soon as the project breaks, I can figure out exactly which file is the project.然后一旦项目中断,我就可以确切地找出项目是哪个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM