- Home /
How to link a class Library project in visual studio with my generated visual studio .sln unity project ?
Hi , by default my scripts open in Visual studio. great.
I am working on a managed dll in another visual studio project .
the codes in my solution project that unity generates uses the namespace which will also be use in my dll.
As things are I have to be working with two identical codes in both projects . In my unity project I work with the code which should be my dll code . I just want my unity project to read the code from my class library project.
I want to delete my script from unity, have my class library project link with my solution that unity generates so that the classes in my unity project that use the namespaces existing in the dll will have access to the namespaces .
How can I do this ?
Answer by UsulPro · Oct 03, 2015 at 04:31 AM
Hi, @DMDev! I use Unity 5 and VS2015 so don't sure about previous versions. The short answer is just put your dll into assets folder and add reference to it in your unity project. After that you can add "using classlibrary" string and work with this namespace.
In more details:
1 check that your library project use 3.5 .net.
2 set the building path to your unity asset folder in project settings
3 open your unity project and add your library project to solution so it will be available each time you open a script in unity
4 after editing code in library project you need to rebuild this project to have access to changes from unity project.
if you want to have access to your Unity proj from library proj you can do the same. But first add solution, build it, then add "UnityProj\Temp\UnityVS_bin\Debug\Assembly-CSharp.dll" to your library project.
okay , I have set the build path to my the desired folder in my assets folder in Unity. Problem is that if i do a build release , the references and a bunch of other unnecessary files get exported into unity too . which is problematic.
How an I only have my dll be exported ?
Yes, you are right! In this case better to leave the build path as it was and add post build event (project properties -> build events):
copy $(TargetPath) YourUnityProject\Assets\Dll\$(TargetFileName)
(the destination folder should exist) It will make copy of your dll automatically each time after building. In this version you can easily use crossover references to share a namespace in both direction.
so i nee to copy the dll at "C:\$$anonymous$$yProjects\Visual Studio\$$anonymous$$ylibrary Library\$$anonymous$$ylibrary \$$anonymous$$ylibrary \bin\Release\$$anonymous$$ylibrary .dll"
to my folder in my unity project under "C:\$$anonymous$$yProjects\Unity\Projects\Valding\Valding\Assets\Classes\VadingClasses"
How do i plug that into copy $(TargetPath) YourUnityProject\Assets\Dll\$(TargetFileName) I tried but failed.
I will accept your answer :) thanks for all the help
copy $(TargetPath) C:\$$anonymous$$yProjects\Unity\Projects\Valding\Valding\Assets\Classes\VadingClasses\$(TargetFileName)
You are welcome! :)