Is there any way to add references to SharedProjects (.shproj) in Unity?

Hey everyone,

I have some SharedProjects (.shproj) to share code between Server and Client (Unity).
How do I add references to those projects in Unity?

Currently, I have to build those projects to .dll files and add them manually to Unity but it takes time and I can’t change shared code inside Unity.

I need a better way to handle it.
Does anyone have a solution for this?

Is shproj still a thing? Just use a .NET Standard (2.0 or 2.1) library instead and make it that the build output points to your Unity assets folder so each time you build the library it’ll overwrite the old one.

Here’s a (long) good video showing how to do it properly (interesting things start at 55:00)

1 Like

I think using Assembly Definitions will get that done for you. Your client code mustn’t depend on the server code assembly, that should be all that’s needed.

You could have a [InitializeOnLoadMethod] in the server assembly that prints Debug.LogError() if you do a client build to confirm that this assembly isn’t in the build.

1 Like

Thank you for the solution. It’s nice but it still needs to build the dll manually and I have to open two projects at the same time (one Client and one to build shared code).
I don’t quite like dll, I want to change shared code directly inside Unity.

Thank you, I think I should put the shared code into a Custom Package and make an Assembly Definition for it.
I just remembered that Custom Package is an alternative to Shared Project in Unity. :wink:

Yeah I was just going to say that: package! :smile:

Make sure you use “Import from disk” otherwise the package will be read-only. The import location can (should) still be in source control of course.