dotnet run 不提供依赖项的静态资产
我遇到了 dotnet run
和静态资产 (contentFiles) 的问题。我有一个 nuget 包(在我的 CI 中构建),仅包含要在其他项目中使用的 CSS 文件。
我所说的“其他项目”是一个 blazorwasm 应用程序,它应该使用这些 css 样式。我遇到的问题是:
当我使用
dotnet run
启动 blazorwasm 应用程序(它启动 Kestrel 服务器来提供我认为的编译文件?)时,带有 CSS 的 nuget 的内容文件是未服务并导致 404(由“css/theme.min.css”引用)。当我使用“dotnetpublish”并启动 nginx docker 来为其提供服务时,这些文件是服务器(当然存储在 wwwroot/css 中)
因为我以前总是使用 dotnet run 来测试我的 blazor 应用程序 - 并且从未遇到过这样的问题 -我有点纳闷。
nuget包的nuspec是:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd" >
<metadata minClientVersion="3.3">
<id>WebTheme</id>
<title>Web Theme</title>
<version>0.1.10</version>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright 2022</copyright>
<contentFiles>
<files include="any/any/wwwroot/css/*" buildAction="Content" copyToOutput="true" flatten="false"/>
</contentFiles>
</metadata>
<files>
<file src="dist/css/theme.css" target="contentFiles/any/any/wwwroot/css" />
<file src="dist/css/theme.css.map" target="contentFiles/any/any/wwwroot/css" />
<file src="dist/css/theme.min.css" target="contentFiles/any/any/wwwroot/css" />
<file src="dist/css/theme.min.css.map" target="contentFiles/any/any/wwwroot/css" />
<file src="dist/css/theme.css" target="content/wwwroot/css" />
<file src="dist/css/theme.css.map" target="content/wwwroot/css" />
<file src="dist/css/theme.min.css" target="content/wwwroot/css" />
<file src="dist/css/theme.min.css.map" target="content/wwwroot/css" />
</files>
</package>
目标应用程序的Program.cs:
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using ManagementApp;
using Microsoft.Extensions.Options;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddOptions();
await builder.Build().RunAsync();
I have a problem with dotnet run
and static assets (contentFiles). I have a nuget package (built in my CI) that only contains CSS files to be used in other projects.
The 'other project' I'm talking about is a blazorwasm app that should use these css styles. The problem I have is:
when I start the blazorwasm app with
dotnet run
(which starts a Kestrel Server to serve the compiles files I suppose?) the content Files of the nuget with the CSS are not served and lead to a 404 (referred by "css/theme.min.css").when I use 'dotnet publish' and start a nginx docker to serve it, the files are server (and stored at wwwroot/css of course)
Since I always used dotnet run to test my blazor apps before - and never had such a problem - I am a bit puzzled.
The nuspec of the nuget package is:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd" >
<metadata minClientVersion="3.3">
<id>WebTheme</id>
<title>Web Theme</title>
<version>0.1.10</version>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright 2022</copyright>
<contentFiles>
<files include="any/any/wwwroot/css/*" buildAction="Content" copyToOutput="true" flatten="false"/>
</contentFiles>
</metadata>
<files>
<file src="dist/css/theme.css" target="contentFiles/any/any/wwwroot/css" />
<file src="dist/css/theme.css.map" target="contentFiles/any/any/wwwroot/css" />
<file src="dist/css/theme.min.css" target="contentFiles/any/any/wwwroot/css" />
<file src="dist/css/theme.min.css.map" target="contentFiles/any/any/wwwroot/css" />
<file src="dist/css/theme.css" target="content/wwwroot/css" />
<file src="dist/css/theme.css.map" target="content/wwwroot/css" />
<file src="dist/css/theme.min.css" target="content/wwwroot/css" />
<file src="dist/css/theme.min.css.map" target="content/wwwroot/css" />
</files>
</package>
Program.cs of the target application:
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using ManagementApp;
using Microsoft.Extensions.Options;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddOptions();
await builder.Build().RunAsync();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论