.NET 9 Maui Blazor Hybrid & Web: Javascript and Reference files

Stephen Braich 0 Reputation points
2025-02-02T08:52:04.4766667+00:00

I have been learning .NET 8 Maui Blazor Hybrid for the past few months to build a multiplatform app for Windows, Android, and iPhone. It's pretty cool, but there was a learning curve. I would like to take advantage of version 9.0 so that I can extend my app to the web.

So far, it seems to start working out of the box.

But, I have two questions:

• Where should I put javascript files?

• Where and how should I reference... reference files?

Javascript Location
I am confused though. Where should I put javascript files? I would have assumed that it would in the .Web project, but there is no wwwroot there. Does it go in the .Shared project? There is a wwwroot, but no index.html to reference the <script>. What about the base project for multiplatform code? There is a wwwroot, and an index.html, but this seems like a strange place to put it.

Reference files
My app uses some large files, including an LLM and some audio files. Currently these sit in the References/raw folder in the base project. I would very much like to keep it there because they are the same files.

User's image

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,657 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,887 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 70,611 Reputation points
    2025-02-02T17:47:56.7166667+00:00

    You should keep the files in a common project, and add a pre build step to copy to the proper folder for each target application.

    see prebuild

    https://learn.microsoft.com/en-us/cpp/build/how-to-use-build-events-in-msbuild-projects?view=msvc-170

    See copy task

    https://learn.microsoft.com/en-us/visualstudio/msbuild/copy-task?view=vs-2022

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.