【问题标题】:Blazor server .NET6 Razor Class Library assets 404 errorBlazor 服务器 .NET6 Razor 类库资产 404 错误
【发布时间】:2022-01-03 19:47:39
【问题描述】:

我有一个 Razor 类库,我已经使用 .NetCore3 和 .NetCore 5 几个月了,没有问题。

在最近将我们的 blazor 服务器应用程序和 Razor 类库更新到 .NetCore 6 后,我在从 Razor 类库加载资产时遇到了问题。

RCL 是通过 nuget 构建和打包的,我可以看到包中的资产,例如;

网络应用程序已更新为使用单个 program.cs,我正在使用 WebApplication.CreateBuilder() 和我的设置选项。

        var builder = WebApplication.CreateBuilder(new WebApplicationOptions
        {
            ApplicationName = typeof(Program).Assembly.FullName,
            ContentRootPath = Directory.GetCurrentDirectory(),
            EnvironmentName = Environments.Development,
            WebRootPath = ""
        });

加载这些资源时出现 404 错误

    <link href="_content/Blurred.Framework.Web.Shared/favicon.ico" type="image/x-icon" rel="icon" />
    <link href="_content/Blurred.Framework.Web.Shared/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link href="_content/Blurred.Framework.Web.Shared/css/site.css" rel="stylesheet" />

我还可以看到 wwwroot 文件夹和相应的资产被加载到 Visual Studio 中的应用程序项目中。

感觉这是一个配置问题,而不是需要更改的重大问题。

ContentRootPathWebRootPath 的正确设置是什么?


更新

根据this,我需要使用我已经完成的app.UseStaticFiles();,以及ConfigureWebHostDefaults中的webBuilder.UseStaticWebAssets();,这在.NET6中没有使用:(

【问题讨论】:

  • 根据您的描述,这是迁移的问题,我们可以理解为如何将存储在.net 6 wwwroot目录中的静态css文件集成到问题?
  • @TinyWang 是的,在 .NET 5 中工作的 RCL 在 .NET 6 中不工作

标签: asp.net-core razor-class-library asp.net-core-6.0


【解决方案1】:

所以我的问题在于 Azure 构建 RCL 解决方案并将 RCL 打包到 nuget 包中的方式。

我必须更新我的构建 YML 以使用 2022 映像以及 .NET 和 nuget 的 v6.0:

改变了

pool:
  vmImage: 'windows-latest'

pool:
  vmImage: 'windows-2022'

并添加

    - task: UseDotNet@2
      displayName: 'Use dotnet 6'
      inputs:
        version: '6.0.x'

改变了

    - task: NuGetToolInstaller@1

    - task: NuGetToolInstaller@1
      inputs:
        version: 6.0.0

改变了

    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'
        vsVersion: '17.0'

    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

【讨论】:

  • Nuget 包的错误是什么?
  • @Rugbrød 这不是包错误,而是构建代理错误。
【解决方案2】:

我有同样的错误。

就我而言,我已将 Nuget 包升级到 .NET 6,但同时更改了程序集 (*.dll),因此它与包名称不同。 因此,资源链接不再起作用。 它指的是程序集名称,而不是 Nuget 包名称。

在我将其更改为两个名称相同后,它起作用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2014-12-21
    • 2020-04-03
    • 2020-01-01
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多