In my unity project, I’m using an external c# dll that i have compiled, copied into the asset directory of my unity project with its pdb file (portable format) beside
While debugging my project from visual studio attach to unity project, I cannot step into the code of the external dll.
Is there a specifiic configuration I"m misssin. The code into my external dll is correcly executed.
I agree. If you can avoid it and have the source code of the library directly into your Unity project, it’ll save you a lot of headaches. This is one of the biggest faults in Unity: bypassing standard Microsoft tools/systems like MSBuild and projects references. But they’re working to fix this in the upcoming switch to .NET 8.
I did not have these “step into my DLL code” issues 5+ years back even with Visual Studio. So it’s got to work somehow.
But I agree, if you can avoid it, don’t make DLLs. Unless … there’s a very specific benefit, as in two cases that I had:
I was able to use regular NUnit for testing math stuff, which sped up Unit Testing by a factor of 100x or so just because NUnit tests were one keystroke and a few ms within the IDE - whereas for Unity it was tab into the editor, wait for 10+ seconds of script compilation, then click buttons and a slow TestRunner.
I was able to interface with Microsoft Office .NET API by decoupling that part of the code, so I could use the same code base for both use cases: within Unity and to do Excel Interop (grab/update data).
Thank’s for all your answer. We use a separate dll beacuse its easier to test and the code could be reused for other applications not build within unity. So I really need to work like this.
Debug JustMyCode is disabled, and I have build my project with Debug mode.
You can still use Unity’s assembly definition files to automatically compile your library as a separate DLL but still have all the source files in your project. That’s how many assets on the assetstore work as well. From a technical point of view it doesn’t really make any difference.
I finally found out how to debug a compiled DLL that is in Assets :
Simply edit the .csproj properties of this DLL to have integrated debugging symbols.
(note : my Visual Studio is not in english, I guessed a few translations here but hopefully you get the idea )
For a project that targets .Net framework 4.8 this is here :
Build / Output / Advanced → set Debug info to “Incorporated”.
I have another project that is in .Net 6, properties are organized slightly differently :
Build / General / Debug symbols → “Incoprporated to DLL”
Rebuild your project and place the DLL in Assets.
Now in the unity console you should get the detailed infos of where things are happening in that DLL.
Breakpoints : debugging using breakpoints works, if you open the external file in the visual studio instance that is attached to unity and set breakpoints from here.
I personnally have one first VS instance for the Assembly-CSharp project that is generated by Unity this is the one I use to attach to unity and debug. I have a second VS instance for all the other .csproj. In order to open files from the compiled DLL and set breakpoints in them, I use F12 on external class names from the first VS instance in order to jump into definitions.
Another way to do it is to go into project references, target the reference corresponding to the DLL to debug, right click on it → Display in object explorer. From here you can navigate to any file.
Here’s how I do it. Hopefully these are all the relevant factors. It’s possible some of these things aren’t required but this works for me.
I’m using Unity 2019 and Visual Studio 2019
In VS, the Just My Code feature is OFF (Tools, Options, Debugging, General)
The DLL is built in DEBUG configuration.
The DLL and the associated PDB are in the Unity project under Class Libraries
I have the Visual Studio project with my Assets/Scripts running in Debug (Attach To Unity)
Under these conditions, when I hit a breakpoint in one of my Unity scripts, I can step into the DLL. Or you can just set a breakpoint in the DLL and it will stop in the debugger (meaning, you don’t have to hit a breakpoint in your Unity script first).
I had to set pdb “Debugging Information” from Full to Portable in the Build/Advanced settings of the class library project properties to make the ‘go to definition’ and debugging step into work.