简体   繁体   English

ASP.Net Core:突然出现数百个构建错误

[英]ASP.Net Core: Hundreds of Build Errors Suddenly

What might cause an ASP.Net Core web application to display hundreds of build errors suddenly without explanation?什么可能导致 ASP.Net Core Web 应用程序突然显示数百个构建错误而没有解释? I started working on an app I had not worked on for awhile and when I clicked publish I got hundreds of build errors that never existed before.我开始开发一个我有一段时间没有开发过的应用程序,当我点击发布时,我遇到了数百个以前从未存在过的构建错误。

Some were quite simple.有些很简单。 Like this block of code used for a Blazor component (file extention .razor) that never had problems before.就像之前从未出现过问题的用于 Blazor 组件(文件扩展名 .razor)的代码块一样。 This block displays red squiggly lined underneath both instances of the string "crumbicon" I can think of no reason why there would be a problem with this:此块在字符串“crumbicon”的两个实例下方显示红色波浪线,我想不出为什么会出现问题:

@using PostAlmostAnything.Models
@crumbicon<a href="@GlobalStatic.SITEURL()">Home</a>

@code {
    string crumbicon = "<<";
}

The exact errors say that there is "ambiguity between filename.crumbicon and filename.crumbicon "the type [blazor file name] already contains a definition for crumbicon". This error has never been encountered before, but now exists on every .razor file that was designed this way.确切的错误说“filename.crumbicon 和 filename.crumbicon 之间存在歧义”类型 [blazor 文件名] 已经包含 crumbicon 的定义”。这个错误以前从未遇到过,但现在每个 .razor 文件都存在是这样设计的。

The other error appear related to various assemblies or variables on pages.另一个错误与页面上的各种程序集或变量有关。 They typically say that something has already been defined someplace else, but if the code were the problem then it would have been an error long ago and not suddenly.他们通常会说已经在其他地方定义了某些东西,但是如果代码是问题所在,那么很久以前就会出现错误,而不是突然出现。

When I try to update Nuget packages they say the updates are not compatible with version 3.1 of .Net Core.当我尝试更新 Nuget 包时,他们说更新与 .Net Core 3.1 版不兼容。

Try to close Visual Studio and reopen.尝试关闭 Visual Studio 并重新打开。 That always works for me to get the libraries back这对我来说总是有用的,可以让图书馆回来

Visual Studio is never stable nowadays.如今,Visual Studio 从来都不是稳定的。 Try cleaning and rebuilding or cleaning obj and bin directories.尝试清理和重建或清理 obj 和 bin 目录。 this may help too这也可能有帮助

Short version: jiggle it until it works.短版:摇晃它直到它起作用。

This happens a lot.这种情况经常发生。 I think it's a conflict between an old assembly that didn't get cleared out of Intellisense and a new one or something like that.我认为这是未从 Intellisense 中清除的旧程序集与新程序集或类似程序之间的冲突。 You can try any / some of:您可以尝试任何/一些:

  • clean and rebuild清理并重建
  • close all open files and re-open them关闭所有打开的文件并重新打开它们
  • just ignore the errors and run the app只需忽略错误并运行应用程序
  • delete the bin folder from your project从项目中删除 bin 文件夹
  • restart Visual Studio重新启动 Visual Studio
  • go get yourself a coffee and wait for Visual Studio to figure it out on its own去给自己喝杯咖啡,等待 Visual Studio 自行解决

Of course, try the other suggestions mentioned in the other great answers here.当然,请尝试此处其他出色答案中提到的其他建议。

Another option is to comment out the offending lines that are giving you problems, then rebuild.另一种选择是注释掉给你带来问题的有问题的行,然后重建。 Keep commenting/building until it works.继续评论/建设,直到它工作。 Once it builds and starts again, uncomment sections one at a time until you are back up and running.一旦它构建并重新启动,一次取消一个部分的注释,直到您备份并运行。

As an extra bonus you may find an errant "}" or missing tag that helped cause the issue in the first place.作为额外的奖励,您可能会发现错误的“}”或丢失的标签首先导致了问题。

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

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