JetBrains / resharper-unity

Unity support for both ReSharper and Rider
Apache License 2.0
1.21k stars 131 forks source link

Assembly definition root namespace behaviour #2427

Open dngulin opened 8 months ago

dngulin commented 8 months ago

Setting the asmdef root namespace doesn't exclude parent directories from namespace providers. So, it just sets a new namespace prefix.

As I remember, it should replace all parent directories. At least that behaviour is described in the source code comment and I believe it used to work this way.

My environment:

citizenmatt commented 8 months ago

Could you provide an example, please? This should generate a .csproj file that contains a root namespace, and that namespace should be used as the root namespace for all files - any folder under the project location will be suggested as a sub-namespace of this custom root namespace.

dngulin commented 8 months ago

The root namespace in the csproj file is the same as in the assembly definition. The problem is that asmdef parent directories work as namespace providers for the project files.

For example, I have two files:

Assets/Modules/Level/Code/Level.asmdef
Assets/Modules/Level/Code/Core/SampleType.cs

The asmdef has the rootNamespace: "Level". In that case for the SampleType I expect to have the Level.Core namespace, but Rider suggest the Level.Modules.Level.Code.Core.

As a workaround I manually disable the namespace provider property for all parent directories, but I believe it used to work without setting them.

imerr commented 1 month ago

Running into this exact problem at the moment as well Our folder structure is _ProductName/Code/Common/SubSystem There's an asmdef in the SubSystem folder which defines a namespace as Product.Common.SubSystem and rider insists on namespacing that to Product.Common.SubSystem._ProductName.Code.Common.SubSystem unless you go through every folder and untick namespace provider (you seemingly have to do this whenever a folder is added too, quite annoying)

Is there any workarounds for that?

JetBrains Rider 2024.1.2 / Unity 2022.3.30