2

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

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

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

Web 应用程序已更新为使用单个 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 中的应用程序项目中。 VS 中的 Web 应用程序

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

ContentRootPath或的正确设置是WebRootPath什么?


更新

据此,需要使用app.UseStaticFiles();我已经完成的,以及webBuilder.UseStaticWebAssets();ConfigureWebHostDefaults.NET6中未使用的:(

4

2 回答 2

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)'
于 2021-11-29T14:51:04.557 回答
0

我有同样的错误。

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

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

于 2022-01-20T11:46:31.870 回答