This question has popped up a few times since Visual Studio 2010’s recent launch. I received it by email overnight from Roland Cox, which is interesting as I’d already planned this post for today.
Do you know how to debug AutoCAD and a custom add in using Visual Studio 2010?
What settings do I need to make? I know the add is getting loaded (the code runs in AutoCAD) but I can't set a breakpoint (it shows a empty circle saying that VS doesn't have the assembly loaded).
I first saw this issue raised a few times on threads with Microsoft, both with respect to AutoCAD and Revit. Jeremy has also posted something on his blog about it.
Adam Nagy, from our DevTech team in Europe, has created this excellent DevNote on the ADN website covering the various options for dealing with this problem. I’ve used this as the basis for the details in today’s post. (Thanks, Adam! :-)
The problem is not at all specific to Autodesk products, although – if the above threads are an indicator – it does seem that as commonly used .NET plugin hosts our products are among the more common environments in which people are hitting this issue.
The cause of the problem boils down to the fact that VS 2010 does not choose the right version of the debugger for Class Library projects targeting prior versions of the .NET Framework: it always uses the default version, the debugger targeting v4 of the .NET Framework. This debugger doesn’t see breakpoints in projects targeting older versions of .NET.
The three workarounds Adam has highlighted show different ways to make VS 2010 use the correct debugger (one which actually hits breakpoints) on these projects. Which solution works best for you will depend on your specific scenario (I would tend to use option 2 or 3, myself).
Solution 1
Start the exe that loads your AddIn (acad.exe, revit.exe, etc) and then attach to it from Visual Studio (Debug -> Attach to Process...)
Solution 2
Modify the config file of the exe that loads your AddIn (acad.exe.config, revit.exe.config, etc) so that it contains the following just before the </configuration> part:
<startup>
<supportedRuntime version="v2.0.50727" />
</startup>
Solution 3
Add the exe that loads your AddIn as an existing project to your solution and set the debugger version for it to v2.0.
- Right-click the Solution in the Solution Explorer and select Add -> Existing Project... and locate the exe that loads your AddIn
- Right-click on the Project that has just been added and select Set as StartUp Project
- Right-click on the Project and select Properties
- Set the Debugger Type to Managed (v2.0, v1.1, v1.0)