【发布时间】: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 中的应用程序项目中。
感觉这是一个配置问题,而不是需要更改的重大问题。
ContentRootPath 或 WebRootPath 的正确设置是什么?
更新
根据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