Debug .NET Components

If you’ve been following along with the preceding example by writing code in Excel and Visual Studio .NET, you’ve probably noticed that you can’t build the .NET project while Excel has a reference to that project’s type library. You need to close Excel or remove the reference each time you make a change in the .NET project. That’s because Visual Studio .NET can’t overwrite the type library while another application is using it.

This makes debugging .NET components from Excel difficult. In fact, it’s not a very good practice. It is a much better practice to add a second test project to your .NET component solution and make that project the start-up project.


Building tests into your development projects is a good practice. In fact, there’s a schoolof thought (called extreme programming) that says you should write tests first, before you implement any feature.

How to do it

To add a test project to the NetForExcel sample, follow these steps:

  1. From Visual Studio .NET, choose File Add Project New Project. Visual Studio .NET displays the Add New Project dialog box.

  2. Select the Console Application template from the VBA project types, give the project a descriptive name, and click OK. Visual Studio .NET creates a folder and template files for the new Windows console application.

  3. Right-click on the new project title in the Solution Explorer and select Set As Startup Project from the pop-up menu, as shown in Figure 5-6. Visual Studio .NET makes the project ...

Get Excel 2003 Programming: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.