Introduction
This is a simple Visual Studio add-in that will automatically close the Start page when you open your solution in Visual Studio.
I love Visual Studio and the Start Page but why there isn't an option to close the Start Page after you open your solution is beyond me. And if you ever need to re-open the Start Page, simply go to the "View" menu and select "Other Windows" and click "Start Page".
Using the Code
To build this application from scratch go into Visual Studio and select "New" Project. Then browse to "Other Project Types\Extensibility" and select "Visual Studio Add-in". Then name your project "StartPageCloser
".
Next the Add-in Wizard will start and for this project, we will select C# code:
Next, only select Microsoft Visual Studio:
Give a good description of your Add-in:
Set your Add-in to load on Startup:
The About dialog box is optional. Then Click finish to start your new Add-in project.
Here is where you will need to add your code. Start by adding the private
variables needed to capture the Open Solution event. You can add this code at the top or the bottom of the Connect
class. You should already be in the Connect
class, if not then open the Connect.cs file.
private Events2 events;
private SolutionEvents solutionEvents;
Next go to the "OnConnection
" event function and add the following code after the line:
_addInInstance = (AddIn)addInInst;
events = (Events2)_applicationObject.Events;
solutionEvents = events.SolutionEvents;
solutionEvents.Opened +=
new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened);
Finally all you need to do is add your SolutionEvents_Opened
function.
private void SolutionEvents_Opened()
{
if (_applicationObject.Windows.Item
(EnvDTE80.WindowKinds.vsWindowKindKindStartPage) != null)
{
_applicationObject.Windows.Item
(EnvDTE80.WindowKinds.vsWindowKindKindStartPage).Close
(vsSaveChanges.vsSaveChangesNo);
}
}
You are now ready to compile and use your new Add-in. After you compile, the Add-in will be added to your Visual Studio Addins folder. This will point to the location of your Add-in DLL. Feel free to change your project to "Release" mode when you are done.
Points of Interest
Sometimes, in order to compile your add-in you will need to close Visual Studio and make sure that it is not set to load your add-in on Startup by going to the "Tools" menu and "Add-in Manager..." and un-checking "Startup" for your add-in. Then close and re-open Visual Studio and open your project. Now you will be able to compile. Just remember to go back in and re-check "Startup" when you are done.
History
- 26th March, 2009: Initial post