-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Reference assembly action should update asmdef files #852
Comments
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. Unanswered questions:
|
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 |
Awesome! That's brilliant to know. And I guess I need to update the asmdef JSON schema, too! |
Oh I would love if it would correctly update the asmdef :) |
Any news on this? |
We're currently planning Rider 2020.3, hopefully we'll include it then. See also RIDER-48660 |
@citizenmatt do you think this will make it to 2020.3? EAP8 doesn't seem to have it (yet). Fingers crossed 🤞 |
Sadly no. This hasn't made it for 2020.3, it's going to be 2021.1 |
Calling out an important detail that's easy to miss from above: consider also adding a package reference when adding an asmdef reference between two packages. This is complicated with optional features, handled by version defines. These are symbols that are defined based on expressions that evaluate if a package is referenced, and what version of that package is referenced. They can be used to add optional features - support for a package wrapped inside defines. In this case, the It doesn't appear to be possible to automatically decide if a package reference should be made. If a reference to a package that is already set up in version defines is required, then it might be an optional feature, or it might be version defines to allow handling multiple versions of the same package - it's still a required feature, but with optional behaviour. Similarly, an optional feature might add a reference to yet another package. It is unlikely that an optional feature should force a required reference, but it would be very hard to check that the consumer of the reference is an optional feature (optional feature or optional behaviour?). A simpler solution is to always prompt to add a package reference. |
Hey Matt, do you have any news on this? Using 2021.2 EAP 7 now and eager to try this :) |
No news, sorry. I'd like to get to this, but it's a larger piece of work that hasn't fitted in to date. |
This feature only works sometimes. Most of the time, the error disappears, but the asmdef is not updated. As soon as I switch to Unity and back, the error re-appears. |
@lgarczyn Yes, unfortunately, it's a bit buggy. We're hoping to address that in the next release, apologies for the inconvenience |
Thanks! It would be nice if the auto-fix also worked on "using" statements and extension methods, and not just missing types. |
Not sure what you mean by that - can you give me an example, please? |
If you are missing an assembly reference, 3 things might show errors. Missing types, unrecognized namespaces and missing extension methods. Currently, rider only offers the "auto-fix" for missing types. |
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?
The text was updated successfully, but these errors were encountered: