【问题标题】:Blazor WebAssembly project, Intellisense pops an error : the type or namespace name 'App' could not be foundBlazor WebAssembly 项目,Intellisense 弹出错误:找不到类型或命名空间名称“App”
【发布时间】:2020-10-26 01:58:50
【问题描述】:

我正在尝试使用 Blazor WebAssembly。 我创建了一个项目,代码是L

public class Program
{
    public static async Task Main(string[] args)
    {
        var builder = WebAssemblyHostBuilder.CreateDefault(args);
        builder.RootComponents.Add<App>("app"); // Error there : The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?)

        builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

        await builder.Build().RunAsync();
    }
}

正如我在代码中评论的那样,智能感知未找到 App 并显示错误。我不能在“App”一词上使用 f12(未找到)。 我可以构建和启动项目,但我想正确清理它。

我关注了这个帖子:Blazor the type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?),但它没有修复它。

我的 IDE 是 Visual Studio Community:Microsoft Visual Studio Community 2019 Version 16.6.2 和 dotnet --version 提供:5.0.100-preview.6.20318.15

非常感谢。

【问题讨论】:

    标签: c# visual-studio blazor-webassembly .net-5


    【解决方案1】:

    确保您的项目使用的所有包都已更新并与 .net 5 兼容。

    更新这两个包为我解决了这个问题:

    Microsoft.AspNetCore.Components.WebAssembly Microsoft.AspNetCore.Components.WebAssembly.DevServer

    【讨论】:

      【解决方案2】:

      根据我的测试,我发现是vs版本的问题。

      建议你使用最新的vs2019预览版打开。

      我用下面的vs2019预览版没有任何问题。

      【讨论】:

      • 非常感谢您的回复,我现在安装预览版并测试
      • 预览版运行良好。非常感谢。
      • 好的,在我为 VS 2019 预览安装了一些扩展之后,错误又回来了。我正在寻找引发此错误的人。
      【解决方案3】:

      按照 Jack J Jun 的建议,我安装了 VS 的预览版。 有效。但是一旦我安装了扩展 CodeMaid,错误就回来了。当我停用 CodeMaid 时,错误消失了。

      【讨论】:

      • 是的,我完全卸载了 Codemaid 并且错误消失了。
      猜你喜欢
      • 2018-10-04
      • 1970-01-01
      • 2019-01-17
      • 2022-06-17
      • 2018-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多