-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maui Hybrid: build fails when adding json file to ./Resources/Raw #17078
Comments
As a workaround, you could move appsettings.json to your project root and make it an embedded resource, then load it from there instead. I don't think this error is maui blazor specific, you would hit the same issue if you had a json file in that folder in a MAUI template app too (those also support appsettings.json as well) |
On the latest preview version, this works using maui without blazor. Using an embedded resource in my case (maui-blazor) also fails with the same error message.
|
…lties # Conflicts: # BolWallet/BolWallet.csproj Also, fixes appsetting.json reference and moves TestAccount.json to root to overcome known issue dotnet/maui#17078
Facing the same issue, it works fine on Android but fails for Ios build |
I'm also facing this same issue when I have an appsettings.Development.json |
Just rename it to .txt, it will work. It is not ideal, but it will atleast get you going, until the issue is fixed |
I am facing the same issue while compiling for <ItemGroup>
<Content Remove="Texts\**" />
<EmbeddedResource Include="Texts\**" />
</ItemGroup> But for each file I receive an error:
Also this is happening for a MAUI library project. On Windows the project compiles successfully. |
This comment was marked as outdated.
This comment was marked as outdated.
I have the same problem with the latest version of Maui and Visual Studio. |
This comment was marked as outdated.
This comment was marked as outdated.
This is still happening with ios and Mac Catalyst, specifically with MAUI Blazor projects. I think it could be due to the "Microsoft.NET.Sdk.Razor" SDK doing weird stuff. Clearly, people are having issues with this, so I'm reopening it. |
This comment was marked as outdated.
This comment was marked as outdated.
is there any workaround on this? I am on MAUI Blazor projects, WinUI and android |
I think I found the workaround, Embedded resource the json file and register it with the help of package // Load appsettings.json
var a = Assembly.GetExecutingAssembly();
using var stream = a.GetManifestResourceStream("MauiAppWithMudBlazor.appsettings.json");
var config = new ConfigurationBuilder()
.AddJsonStream(stream)
.Build();
builder.Configuration.AddConfiguration(config);
builder.Services.Configure<AppSettings>(config.GetSection("AppSettings"))
.AddSingleton(s => s.GetRequiredService<IOptions<AppSettings>>().Value)
.AddSingleton<IAppSettings>(s => s.GetRequiredService<IOptions<AppSettings>>().Value); https://github.com/spajce/.NET-MAUI-Blazor-Hybrid-app-with-MudBlazor |
@spajce I am not sure how that helps. My files are not configuration files and they are already |
Might be potentially helpful, but it is happening in my Hybrid project too when building for ios with a .json file in my Raw Assets. Here is the run: Changing from a .json to a .txt did fix it |
Also just ran into this building a Blazor ("Hybrid") app for iOS. I had two JSON files in my Resources\Raw folder, and the build failed. Changing the file extension to ".txt" allowed the compilation. It would be nice to have this resolved for the sake of code/architecture maintenance and readability, so that someone doesn't come into a code base to be surprised that a TXT file is actually JSON content. |
I got the issue appsettings.json : error : The path '../../../../../../../../../Users/xxxxx/Projects/SalesMauiSource/SalesMauiApp/appsettings.json' would result in a file outside of the app bundle and cannot be used. When build .net maui blazor hybid for IOS on Visual Studio Code in Mac Os. |
Hi @Redth, |
This bug is also preventing me from compiling iOS apps with |
Here is the correct code, Maui uses "Condition" to everything, just put "Remove" over "Include", Working on Mac iOS simulator and Windows Android Simulator, i don't tried out on Mac Android simulator because just need iOS on it. On IOS has to be 2x with "Content" and "GoogleServicesJson" if you use MauiMTAdmob plugin.
|
@Marckxp this doesn't work (just tested). The mere presence of the file would result in the error no matter if your project refers to it or not. See above comments. |
I'm hitting this too. I wanted to include a json file in the Raw folder but it errors. Changing to a txt fixes the issue. |
I'm also encountering this with json files and maui hybrid. Yes, changing the file extension to .txt is a temporary workaround but this is a major pain point. |
@mkArtakMSFT Any thoughts on this one? Thanks! |
For google-services.json error, adding following lines worked for me. Thanks @Marckxp for showing the direction.
|
UPDATE: confirmed that google-services.json is good (i.e. no error happens). My error was due to tsconfig.json, and google-services.json error happen because I put back the file as |
@javiercn can you please add this to your todo list. Want to make sure we understand what's causing the issue and direct it as necessary. |
I'm also having this issue using MAUI Blazer Hybrid when using appsettings.json as an embedded resources. Please fix it. |
Was there a fix to the appsettings.json bug using Maui Blazor Hybrid? It's November 2024! |
Hello guys! Here at the company we had a similar problem and we had to solve it with relative paths. When the iOS build is done, the entire .net debug structure is in the wrong folder. If you open the bin folder after the iOS build, you will see that the following folders have been created, Debug and iOS. As iOS is built in Objective C, the multi-threaded behavior structure is not as well accepted as in C# or Java. So, MAUI separates the worlds. In this separation, this problem occurs. To resolve this, all iOS assets need to be placed within the Platforms/iOS/Resources folder. This way the build will be able to resolve the paths to the assets. And maybe, very maybe, you may have the LongPathEnabled problem, if you are using Windows. Follow the step-by-step instructions on this Autodesk link and magically your project will work! P.S: Builds will have to be via CLI. |
Co-authored-by: James Lloyd <[email protected]>
Description
I am trying to create an appsettings.json file for my maui-blazor application. I'm doing this by adding it to my Resources/Raw folder.
the file is already marked as an asset through this line
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
This is happening on a mac and as far as i know only with json files, when i rename it to .txt, the project builds.
This does not happen on a normal maui application, only with maui-hybrid did the problem occur.
Steps to Reproduce
1. Create app with
dotnet new maui-hybrid
<TargetFramework>net8.0-maccatalyst</TargetFramework>
2. Add a json file to the Resources/Raw folder
3. Build with
dotnet build
or build with IDEThe error message i am getting is:
Resources/Raw/aps.json : error : The path '../../../../../../../../../Users/xxxxx/Desktop/Werk/projecten/App/Resources/Raw/appsettings.json' would result in a file outside of the app bundle and cannot be used. [/Users/xxxxx/Desktop/Werk/projecten/App/App.csproj] Resources/Raw/aps.json : error : [/Users/xxxxx/Desktop/Werk/projecten/App/App.csproj]
Link to public reproduction project repository
No response
Version with bug
8.0.0-preview.7.8842
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
macOS
Affected platform versions
14.0
Did you find any workaround?
Rename it to .txt i guess
Relevant log output
No response
The text was updated successfully, but these errors were encountered: