Hi folks!
I want to share some .cs class files between the server project (VS 2015 only) and the client project (Unity 5.2.1 together with MS Visual Studio Community 2015).
By sharing, I mean that the according class file does physically only exist in one project, but is linked into the other project. You can achieve this in VS by adding an existing item and then select “add as link” from the dropdown of the Add-button.
Unfortunately, if I link files into my Unity-project that way, they are removed again from the project by Unity.
Is there a way to tell Unity to accept such linked files when saving the project?
Unity regenerates the project files periodically (not completely sure under what circumstances - probably anytime anything is added or move around). I don’t believe Unity supports linking like that.
You might be able to do something with a symbolic link, which is part of the OS. It will make Unity think the file physically exists in both places. The concept exists (and probably originated in) Linux as well.
I’ve not used them in the context of Unity, but I can’t think of a reason it wouldn’t work.
Hi Dave,
thanks for your advice!
I have tried using both, symbolic and hard links, but after testing for almost two hours with parallel opened Visual Studios, I have finally given up.
Here is a quick summary of my findings - hope it might be of any help to someone.
Problem is that both link types seem not to be fully tranparent when it comes to changes to the file.
That means if one project modifies the real file, then the other VS-session using the link will not notice the change.
I was almost expecting this for symbolic links after I saw that such a link has its own timestamp and even filetype (SYMLINK, but it’s not a filename extension).
But also for hard links it is almost the same, as the file-change is only communicated to observers of the link, when you highlight the link in Explorer and it then refreshes its timestamp.
Even stranger is the other direction, when the file is modified via the link:
Here, the symolic link works better, and the VS using the real file noticed changes immediately.
For the hard link it is the same as before: Changes are only communicated as soon as Explorer notices that the file has changed. And this doesn’t seem to happen by itself, even if I waited for some minutes.
This behaviour is far from what I’d call ‘reliable monitoring’.
And I didn’t even mention the consequences on the synchronization with my cloud-storage…
My personal workaround is easy though, because only one of the projects is a Unity-project:
I simply keep the files in the client project (Unity/VS) and link them into the server project (VS alone), using VS’s built-in link feature.
It’s not the best solution, as I’d prefer to have all relevant files in the server-project, but at least it works without the danger of data-loss!
Greetings!
reinski