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 startup project. To add a test project to the NetForExcel sample, follow these steps:
From the File menu, choose Add Project, New Project. Visual Studio .NET display the Add New Project dialog box.
Select the Console Application template from the Visual Basic 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.
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 25-6. Visual Studio .NET makes the project name bold, indicating it is the startup project.
Add code to the test project’s
Mainprocedure to test the .NET component.
For example, the following code tests the NetString class from the NetForExcel component created earlier:
' .NET test ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access