是否可以通过 .csproj 文件从 .NET Maui Blazor 混合应用程序的构建中排除 razor 页面?

问题描述 投票:0回答:1

好吧,我一直在尝试设置配置 Maui Blazor 混合应用程序,这是我很陌生的东西。

我有一些视图需要针对某些构建配置进行自定义。因此,我希望通过 .csproj 文件在某些构建条件下有选择地排除 razor 页面,以便我可以在不同的 razor 页面中使用相同的路线,并且每个构建中只有其中一个页面最终出现,从而自动生成正确的视图根据现有文件选择。

我已经检查了 Microsoft 的文档 关于 .NET Maui 中的多目标,其中描述了一种根据

.cs
文件中的
<ItemGroup>
项目条件排除
.csproj
文件的方法。

我现在已经建立了一个小型测试项目,并尝试使用类似的方法排除剃刀页面,但它不起作用。我会收到一条错误消息,告诉我路线不明确,因为这两个文件都包含在构建中,这意味着

<Compile Remove>
显然不起作用。错误如下:

The following routes are ambiguous:
'' in 'MyApp.Components.Pages.Home_Dupe'
'' in 'MyApp.Components.Pages.Home'

   at Microsoft.AspNetCore.Components.RouteTableFactory.DetectAmbiguousRoutes(TreeRouteBuilder builder)
   at Microsoft.AspNetCore.Components.RouteTableFactory.Create(Dictionary`2 templatesByHandler, IServiceProvider serviceProvider)
   at Microsoft.AspNetCore.Components.RouteTableFactory.Create(List`1 componentTypes, IServiceProvider serviceProvider)
   at Microsoft.AspNetCore.Components.RouteTableFactory.Create(RouteKey routeKey, IServiceProvider serviceProvider)
   at Microsoft.AspNetCore.Components.Routing.Router.RefreshRouteTable()
   at Microsoft.AspNetCore.Components.Routing.Router.Refresh(Boolean isNavigationIntercepted)
   at Microsoft.AspNetCore.Components.Routing.Router.RunOnNavigateAsync(String path, Boolean isNavigationIntercepted)
   at Microsoft.AspNetCore.Components.Routing.Router.<>c__DisplayClass76_0.<RunOnNavigateAsync>b__1(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

我相信这是因为实际显示的内容是在构建过程生成的

_razor.g.cs
文件中找到的。然后我尝试用
<Compile Remove>
排除那些生成的文件,这也不起作用。很可能是因为它们甚至不是项目的一部分,但那时我已经没有想法了。

这是我当前的

.csproj
文件的相关部分,此时它只是尝试从构建中删除第二个 razor 文件:

<ItemGroup Condition="true">
  <Compile Remove="**\*.Dupe.razor" />
</ItemGroup>

这是我在尝试删除构建期间生成的

_razor.g.cs
文件时使用的相应片段:

<ItemGroup Condition="true">
  <Compile Remove="**\*_Android_razor.g.cs" />
</ItemGroup>

我知道在第二个片段中,至少路径是错误的,但是是否有一种方法可以通过

.csproj
文件中的相对路径访问这些文件?如果路径正确,以这种方式删除这些文件是否有效?我对如何构建 razor 页面的了解非常有限。

由于没有想法,我也尝试过

<Content Remove>
而不是
<Compile Remove>
,这也不起作用并导致上述相同的错误,但确实从 Visual Studios 解决方案资源管理器中删除了该文件。

是否有某种既定方法可以通过 .csproj 文件根据页面文件名从构建中排除 razor 页面?

c# .net maui csproj
1个回答
0
投票

对于任何遇到这个问题并关心解决方案的人,我现在在 this github repo 中找到了解决方法。这显然是 .NET MAUI 中使用 WebView SDK 的一个(不太清楚)已知问题

© www.soinside.com 2019 - 2024. All rights reserved.