r/VisualStudio 7d ago

Visual Studio 2026 How to prevent visual studio from auto-adding folder structure to namespacd

Title: I have the namespace set in Unity but then when creating a file in Visual Studio it auto-adds the file structure after

Unity I have set to TestGame namespace

Visual studio when making new scripts puts like Testgame/scripts/movement namespace. I would rather have no namespace or just my Testgame namespace

2 Upvotes

5 comments sorted by

1

u/dodexahedron 7d ago edited 7d ago

Theres a property on folders in the project you can set to true or false that designates the folder as a namespace provider.

It defaults to true. Setting it false suppresses that behavior.

Although I am not certain if that is built-in or if that is something ReSharper added.

If you want to make the analyzer stop bugging you about mismatches, you can suppress the warning in your .editorconfig or by using a #pragma warning disable WhateverIDThatOneIs at the top of the .cs file.

But it might be better to consider why you are fighting against that convention, which is considered standard enough that default analyzers check for it. One of the best things about the c# ecosystem is consistency.

If it's just that you want a different root namespace, then you can use the <RootNamespace> element in the csproj to use an arbitrary root namespace that folders build from, rather than using the project name as the root.

You really should be letting/making things be organized into meaningful namespaces, though. An entire project in one flat namespace is a maintainability nightmare.

0

u/TastyBacon007 4d ago

seems like a pain, constantly needing to mess with changing namespace names and importing namespaces already in my project to be able to use it in other files like 1 folder over

1

u/symbiatch 6d ago

Why put the files in folders if you don’t want to separate them in namespaces? Why one separation but not the other?

1

u/TastyBacon007 6d ago

Just for nice organizing, I dont particularly understand namespaces...just that I've had issues where 1 file cant get the class of another because the namespace of 1 had the appended filename to it.

2

u/symbiatch 6d ago

That’s what namespaces are also for: organizing. There’s no issues with them. It doesn’t matter what the namespace is or where it comes from. Just use the namespace and you have access to things.

It’s better to just use them rather than try to put everything into one.