Does default directory structure for .net Blazor have to stay?

Viewed 55

I am very new to working with C# and the blazor. (I do have experience working with Svelte, react and other frameworks. But none with C#.

I was curious if/how I can create my own folder structure from the templated structure it gives when you run dotnet new blazorwasm.

.vscode/
bin/
obj/
Pages/
Properties/
Shared/
wwwroot/
_Imports.razor
Program.cs
Program.csproj
Project.sln

Following the tutorials microsoft has, they just put scripts into the root folder, which I do not like.

Any advice would be appreciated thanks!

EDIT: @andrew wynn Okay I understand. But outside of the wwwroot folder, can I take and move folders into other folders like Pages or Shared which contain razor component files? Something like this? Because from what I can tell I don't see anything linking them directly. It looks like everything is linked via namespaces if I am understanding it correctly.

.vscode/
bin/
obj/
Pages/
Properties/
Shared/
wwwroot/
_Imports.razor
Program.cs
Program.csproj
Project.sln
2 Answers

wwwroot is the root directory for the site, so it's where all of the source files go. They can go into subdirectories in there as long as they are referetially linked.

You can make some middleware to use a different folder if you wish though, see [this link][1]

Edit:

So each of the folders in a Blazor project is for a specific set of files. Pages is there for the .blazor and .cshtml files, these don't exist on the public facing site as they are dynamically translated into html when requested.

I'm not entirely sure what it is you would like to acheive. The folder structure is hard coded into the server host application. The static components (javascript, css, html, images etc) all go into wwwroot as they can be accessed directly by clients, the content to dynamically generate by ASP.NET or Blazor is in Pages, your classes and such go in Data... Do you just want to rename these folders? . [1]: JS File outside www root folder

I have figured it out. Yes you can structure it how ever you want. You just to make sure you update the _imports.razor file to reference the new location.

So if I move everything into a Source folder I would need to update.

@using MyProject.Shared

//TO
@using MyProject.Source.Shared

And then make sure to add any new files that need referenced.

Related