0

我正在尝试使用 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 找不到类型或命名空间名称“App”(您是否缺少 using 指令或程序集引用?)但它没有修复它。

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

非常感谢。

4

3 回答 3

3

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

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

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

于 2020-11-22T13:04:51.347 回答
0

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

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

我使用了以下vs2019预览版没有任何问题。

在此处输入图像描述

于 2020-07-07T08:02:49.153 回答
0

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

于 2020-07-12T00:08:11.837 回答