我有一个 Razor 类库,我已经使用 .NetCore3 和 .NetCore 5 几个月了,没有问题。
在最近将我们的 blazor 服务器应用程序和我们的 Razor 类库更新到 .NetCore 6 之后,我在从 Razor 类库加载资产时遇到了问题。
RCL 是通过 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 中的应用程序项目中。
感觉这是一个配置问题,而不是需要更改的重大问题。
ContentRootPath
或的正确设置是WebRootPath
什么?
更新
据此,我需要使用app.UseStaticFiles();
我已经完成的,以及webBuilder.UseStaticWebAssets();
在ConfigureWebHostDefaults
.NET6中未使用的:(