use Shared Project (.shproj) in unity

Hello!

there is a useful type of project called “shared project” in visual studio. I have a shared project with many classes that are shared between projects. its benefit is that it is only code and every referencing project get codes and compile them with its settings and target platform. and you don’t need to create separate builds with various settings and copy DLLs for different projects. it is especially useful for network and socket programming.

I have a Shared Project containing some socket classes useful for online games. but there is a problem. unity solution doesn’t have a reference option! the auto-generated “Assembly-CSharp” doesn’t support adding a reference.

now I have two bad options:
1- create a DLL and put it into plugins.
2- copy/paste all codes into the Assets folder.

considering that all classes in this shared project are used by two parties, the Client (unity game) and the server, and they are under development, it is very time-consuming to build DLL for both sides and put them in their respective destination (i know that I can use post-build action commands). also, the copy/paste of codes is worse.

is there a way to add a “shared project(.shproj)” to a unity project???

thanks in advance!

I very much doubt it. In addition to the DLL method and copying source code, you do have the additional option of creating a Unity Package:

https://docs.unity3d.com/Packages/com.unity.package-manager-ui@1.8/manual/index.html

1 Like

I agree with @PraetorBlue that an UPM package is probably the best option.

There’s a general misconception here. Unity does not have a csproject it uses. The csproj files Unity creates are only for IDE support. Unity compiles it’s assemblies “manually” by invoking the compiler with the necessary sources files and parameters. You can create an “mcs.rsp” file in your Unity project if you need specific compiler options, though I doubt that you can link another shared project this way. If the shared projects are supported by the compiler itself, it may work. If it’s a VisualStudio project feature it won’t work.

1 Like