简体   繁体   English

.NET MAUI Blazor 如何更改 HostPage 位置

[英].NET MAUI Blazor how to change HostPage location

I'm attempting to place the Blazor website into a separate directory within the MAUI application to create separation (and in future use it as a GIT submodule).我正在尝试将 Blazor 网站放入 MAUI 应用程序中的单独目录中以创建分离(并在将来将其用作 GIT 子模块)。

But I don't seem to be able get MAUI to recognize a different BlazorWebView 'HostPage' reference than the default of wwwroot/index.html, does anyone know how to set this to this subdirectory location?但我似乎无法让 MAUI 识别与 wwwroot/index.html 的默认值不同的 BlazorWebView 'HostPage' 引用,有人知道如何将其设置为此子目录位置吗?

MAUI 应用程序中 Blazor 站点的目录结构

Current code for MainPage.xaml, it compiles and runs but gives 0.0.0.0 can't be found; MainPage.xaml 的当前代码,它可以编译并运行,但找不到 0.0.0.0;

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:MauiApp1.ImagineItsASubModule"
             x:Class="MauiApp1.MainPage"
             BackgroundColor="{DynamicResource PageBackgroundColor}">
    <BlazorWebView HostPage="ImagineItsASubModule/wwwroot/index.html">
        <BlazorWebView.RootComponents>
            <RootComponent Selector="#app" ComponentType="{x:Type local:Main}" />
        </BlazorWebView.RootComponents>
    </BlazorWebView>
</ContentPage>

Figured out my issue, posting here for any future people having issues.想通了我的问题,在这里发布给任何未来有问题的人。

Due to copying/importing the html/css etc the 'Build Action' on the files are set to 'None' so when build happened they naturally didn't come with the compile.由于复制/导入 html/css 等,文件上的“构建操作”设置为“无”,因此当构建发生时,它们自然不会随编译一起提供。

In order to do this I added the item group to my csproj file;为了做到这一点,我将项目组添加到我的 csproj 文件中;

<ItemGroup>
    <Content Include="ImagineItsASubModule\\**\*.*" />
</ItemGroup>

Now the files required come across and Blazor starts as expected, might need to mess with the regex to make sure that certain items are included/excluded as required.现在需要的文件出现并且 Blazor 按预期启动,可能需要弄乱正则表达式以确保根据需要包含/排除某些项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM