VisualStudio 2022 v17.2.3 has suddenly started changing the namespaces of my C# files when I drag them to a different directory. In the process it also deletes/adds/modifies using statements (often deleteriously) and updates every file referencing the moved file. It's changing the namespace to the ProjectName.FolderPath.
Searching Tools > Options has turned up nothing. I've disabled all extensions in case one of them was responsible, but it's had no effect. How can this behaviour be stopped?
To disable this globally, go to
Tools > Options > Projects and Solutions > General
and untick the box near the bottom next to "Enable namespace update when moving files". There is a bug in VS2022 that prevents this option being displayed when searched.
If you need to disable the namespace update on a per file basis (as opposed to the global setting) then you can add the following directive to the file:
#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace This.Namespace.Stays.Intact
{
// ...
}
From the first glance it disables the warning, but it also disables the namespace update for that file. Which is super handy when you want to exclude that single file from being modified on, say, namespace sync.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With