Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Reference assembly action should update asmdef files #852
Rider has a very convenient "Reference 'assembly' and use 'type'" quick-fix action when you're trying to use a type from a non-referenced assembly. That kicks in for types from other asmdef-generated assemblies, but since Unity uses the asmdef file's references to generate .csproj references, the asmdef file has to be updated by hand to make the code compile in Unity.
Ideally, the reference assembly action should update the asmdef file automatically. Is that doable?
This should be possible. If the reference being added is to another
If the reference being added is an assembly reference, then we'll need to see if that assembly is from a .asmdef in a read only "referenced" package. If so, modify the .asmdef and add the assembly reference to the project.
You can see somewhat out of date code for this in the resharper-nuget project. It's circa ReSharper 8, and got rolled into the product for ReSharper 9. I don't think much has changed.
For your first question: yes, there are - all of the ones from Unity's packages system. The rules for those are:
This means that if you want to filter for assemblies that should be automatically added to an asmdef, you need to look though all other asmdef files in the project, and the manifest.json file of the project.
For your second question: seems like it. If I have a reference to assembly A in assembly B, Rider won't suggest that I add a reference to assembly B in assembly A. So that should be safe.
The first question is really determining if there is ever a scenario for trying to add a purely binary reference to a
What I mean by "purely binary reference" is an assembly that isn't part of a package, or isn't already referenced. Plugins and other .dll assets are already referenced, so we're good there. Source packages are
Cached packages are a little different. To ReSharper, they'll look like a simple binary file reference, but we need to know better. Cached packages are still
The problem is if the binary reference doesn't match a
The good news is that the assembly name is the same defined name in the
I suspect that if we're modifying a
In 2018.3+, there is something like a "purely binary reference" in asmdef files.
In the .meta file for that DLL, you'll have this
Now, you can use the "Assembly references" list in the asmdef import settings to add a reference to that
Here's how it looks like in the UI
and what the .asmdef file itself looks like
Note that the
DLLs with the "auto reference" switch disabled will not be added to any custom assembly unless you add them in the "assembly references" list.
I'm not sure about the "normal" Unity assemblies (non asmdef based). My guess is that the DLLs will still be referenced (since there's no way to configure the normal assemblies).