asp.net 运行 标签中的核心 6 个奇怪属性

asp.net core 6 strange attributes in tags when run

我有一个 VS2022 asp.net 核心 6 网络应用程序,它在 运行 时的许多 _Layout.cshtml 标签中具有无效的 html 标签属性 (b-g6ltozs93r)。这是一个未受影响的项目的示例。 VS2019/.net5 或更早版本不会出现这种情况。发生在调试或发布、本地发布到文件夹或 Web 部署到服务器时。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Home page - WebApplication1</title>
    <link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/site.css?v=sjk3m9Ugj7rjYsMBDEOUmfKesxbo63CbCXLz0gPFM6c" />
</head>
<body>
    <header>
        <nav b-g6ltozs93r class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
            <div b-g6ltozs93r class="container">
                <a class="navbar-brand" href="/">WebApplication1</a>
                <button b-g6ltozs93r class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                        aria-expanded="false" aria-label="Toggle navigation">
                    <span b-g6ltozs93r class="navbar-toggler-icon"></span>
                </button>
                <div b-g6ltozs93r class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                   ...
                </div>
            </div>
        </nav>
    </header>
    <div b-g6ltozs93r class="container">
        <main b-g6ltozs93r role="main" class="pb-3">
            
<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>

        </main>
    </div>

    <footer b-g6ltozs93r class="border-top footer text-muted">
        <div b-g6ltozs93r class="container">
            &copy; 2022 - WebApplication1 - <a href="/Privacy">Privacy</a>
        </div>
    </footer>

    <script src="/lib/jquery/dist/jquery.min.js"></script>
    <script src="/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="/js/site.js?v=4q1jwFhaPaZgr8WAUSrux6hAuh0XDg9kPS3xIVq36I0"></script>

<script src="/_framework/aspnetcore-browser-refresh.js"></script></body>
</html>```

这是 .net 6 的新功能 CSS Isolation

如果您不想这样,您可以在 .csproj 文件中添加 <ScopedCssEnabled>false</ScopedCssEnabled>,如下所示。我已经测试过了,它对我有用。

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <ScopedCssEnabled>false</ScopedCssEnabled>
  </PropertyGroup>

</Project>