我正在使用最新的WebAssembly(WASM) 托管Blazor应用程序的预览版。我已经设置了一个WASM托管的应用程序,并在客户端应用程序文件夹的wwwroot/index.html
文件中配置了一个基本的href
为/App1/
:
<base href="/App1/" />
目前,我的应用程序结构如下:
- 客户端
- 服务器端
- 共享的
接下来,我将服务器应用程序文件夹中的应用程序映射到路由:
app.Map("/app1", app1 =>
{
app1.UseHttpsRedirection();
app1.UseBlazorFrameworkFiles();
app1.UseStaticFiles();
app1.UsePathBase("/app1");
app1.UseRouting();
app1.UseIdentityServer();
app1.UseAuthentication();
app1.UseAuthorization();
app1.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
});
通过对启动设置的一些更改来映射到 /app1
,效果非常好。接下来,我复制了客户端应用程序并更改了名称空间和 csproj
为 App2
。
现在我的应用程序结构如下:
- App1(客户端应用程序)
- App2(客户端应用程序)
- 服务器
- 共享文件夹
我将基本的 href
设置为 /App2/
,并在服务器启动时添加了第二个映射:
app.Map("/app1", app1 =>
{
app1.UseHttpsRedirection();
app1.UseBlazorFrameworkFiles();
app1.UseStaticFiles();
app1.UsePathBase("/app1");
app1.UseRouting();
app1.UseIdentityServer();
app1.UseAuthentication();
app1.UseAuthorization();
app1.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
});
app.Map("/app2", app2 =>
{
app2.UseHttpsRedirection();
app2.UseBlazorFrameworkFiles();
app2.UseStaticFiles();
app2.UsePathBase("/app2");
app2.UseRouting();
app2.UseIdentityServer();
app2.UseAuthentication();
app2.UseAuthorization();
app2.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
});
然而,该项目无法运行。它抱怨静态文件仍然被合并在一起。在使用
dotnet run
运行服务器项目时,我收到了这个编译错误:/usr/local/share/dotnet/sdk/3.1.201/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(191,5): error : Conflicting assets with the same path '/appsettings.Development.json' for content root paths '/Users/user/Developer/WasmHosted/App1/wwwroot/appsettings.Development.json' and '/Users/user/Developer/WasmHosted/App2/wwwroot/appsettings.Development.json'.
我也尝试添加commandLineArgs
在客户端应用程序的launchsettings
中以更改内容根目录位置,但没有效果:
"commandLineArgs": "--contentroot=/app1",
任何建议都将不胜感激,因为我不知道还能尝试什么。
这是我用来创建项目的
dotnet new
命令。dotnet new blazorwasm -au Individual -ho -n WasmHosted
<StaticWebAssetBasePath>
中。这个问题可能会证明有用https://github.com/dotnet/aspnetcore/issues/20580 - Xeevis