Ahune ajé o ahe
Ahune ajé o ahe

Reputation: 141

Error: The path would result in a file outside of the app bundle in .NET MAUI Blazor project

I'm working on a .NET MAUI Blazor project, specifically the NativeClients part of the project. My Razor components are organized in the HikaridoConnect.Shared project under the Pages folder, and the MAUI project itself is located at HikaridoConnect.NativeClients\HikaridoConnect.NativeClients.

I encountered the following error message:

Error: The path '../../../../../../../work/1/s/HikaridoConnect.Shared/Components/MediaComponent/MediaTabPanel.razor' would result in a file outside of the app bundle and cannot be used.

I believe this error is related to the relative paths used within my Razor components, but I'm not sure how to resolve it. How can I address this error and ensure that my Razor components are correctly located within the app bundle?

Any guidance or suggestions on how to fix this issue would be greatly appreciated. Thank you!

Yaml code shared - https://codeshare.io/9ORD60

Upvotes: 0

Views: 935

Answers (1)

SiddheshDesai
SiddheshDesai

Reputation: 8157

According to this githubissue1 and this githubissue2

The relative routes utilised by your Razor components are the cause of the error message you are getting. Make sure your Razor components are properly positioned within the app bundle in order to fix this issue. Using the @using directive to specify the namespace in which your Razor components are located is one method to accomplish this. For instance, You can add the code below at the top of your Razor component if it is situated in the HikaridoConnect.Shared.Pages namespace:

@using HikaridoConnect.Shared.Pages

Specifying the path of your Razor component in the @page directive is another approach to fix this issue. You can add the following line at the top of your Razor component, for instance, if it is located at HikaridoConnect.Shared/Components/MediaComponent/MediaTabPanel.razor:

@page  "/Components/MediaComponent/MediaTabPanel"

Also, Refer this SO thread answer by Falco Winkler

Refer this blog for building maui in Azure pipelines.

My yaml script:-

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  solutionPath: '$(System.DefaultWorkingDirectory)/MauiApp1.sln'
  configuration: 'Release'

jobs:
- job: BuildAndPublish
  displayName: 'Build and Publish .NET MAUI Blazor App'
  steps:
  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '7.x' # Use the .NET 7 SDK

  - script: dotnet workload install android
    displayName: 'Install .NET MAUI workload for android'

  - script: dotnet build --configuration $(configuration) $(solutionPath)
    displayName: 'Build .NET MAUI project'

  - script: dotnet publish --configuration $(configuration) $(solutionPath) -o '$(build.artifactStagingDirectory)'
    displayName: 'Publish .NET MAUI project'

  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(build.artifactStagingDirectory)'
      ArtifactName: 'drop'
      publishLocation: 'Container'

Upvotes: 1

Related Questions