resharper-unity
resharper-unity copied to clipboard
Assembly definition root namespace behaviour
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:
- Unity 2023.1.19f1
- Unity package
com.unity.ide.rider3.0.26 - JetBrains Rider 2023.2.2 (#RD-232.9921.83)
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.
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.
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
I've came across the same problem with custom packages installed locally in a project. To install a custom package locally, the Unity team suggest to put it under the Packages/mycompany.package-name directory.
Then, according to their documentation they recommend to put the tests under the Tests/Runtime (or Tests/Editor) folder together with its asmdef.
I've done these steps and set the root namespace accordingly. For editor tests it is set to MyCompany.MyPackage.Editor.Tests. However, when I open the project in Rider (2024.1.2) it wants me to change the mentioned namespace to MyCompany.MyPackage.Editor.Tests.Tests.Editor.
It seems somewhat correct because when I switch to the Solution view, the given project says that the files are in the following folder hierarchy: Packages / mycompany.package-name / Tests / Editor despite the asmdef is located at the same place (next to the cs files).
So I'm not sure that my problem is actually the same, but the other might have experienced the same and the root cause might be the same.