Fast Solution Build Add-in for Visual Studio .NET






4.50/5 (22 votes)
Dec 4, 2002
7 min read

87075

1231
Performs VC6-style dependency checking for VS .NET multi-project solution builds
New versions of Fast Solution Build may be found on http://workspacewhiz.com/ in the Other Add-ins section.
Introduction
When making the transition from Visual C++ 6 to Visual Studio .NET, it became evident multi-project solution builds were quite a bit slower than their Visual C++ 6 counterpart workspaces. For people working in a single project environment, the difference is negligible. For multi-project solutions, the pain of using the Build Solution command quickly becomes obvious, while waiting for all the "dependency checking" for every project of the solution.
Fast Solution Build emulates the Visual C++ 6 build style. It builds on
the concepts from the original Fast Project Build VBScript macro, while
providing more ease of use and error checking. In
addition, the Debug
command is now available.
Features
- Quickly identifies and builds just those projects that have changed files.
Unlike the
Build Solution
command, no slow per project full solution dependency checks are performed. - If an error occurs during the build of a project, the build shuts down immediately. The rest of the solution's projects do not continue building.
- The equivalent of
Debug.Start
is available through the Run Active Project command. UnlikeDebug.Start
, a slow full solution dependency check is not performed. - If a debug session is active, the user is prompted to shut down the debug session before the build starts.
- Also shows an example of "proper" add-in installation/uninstallation.
Installation without the Installer
- Unzip the archive.
- Close down Visual Studio .NET.
- Run
regsvr32 FastSolutionBuild.dll
.
The installer offers much more ease of use, including an uninstall feature, and should be used where possible.
Setting Up Keyboard Bindings
- Reopen Visual Studio .NET.
- Choose to either accept or not accept the default Fast Solution Build keyboard bindings.
- If desired, you may install a key binding for the macro:
- Go to Tools->Options->Keyboard.
- If the keyboard-mapping scheme has never had a custom copy made, press the Save As button and name your key bindings.
- In Show commands containing:, type FastSolutionBuild.
- Click on FastProjectBuild.Connect.BuildActiveProject.
- Go to Press shortcut key(s).
- Press F7 (or your desired key).
- Click Assign.
- Click on FastProjectBuild.Connect.RunActiveProject.
- Go to Press shortcut key(s).
- Press F5 (or your desired key).
- Click Assign.
- Click OK.
Usage
The bold project in the Solution Explorer is the top-level
project built by the Fast Solution Build macro. To make a different project
the "startup" project, right click on the desired project and choose
Set as StartUp Project
.
Run Fast Solution Build's BuildActiveProject or RunActiveProject commands from the Tools menu or press the keyboard key assigned to the add-in commands.
Technical Details
Fast Solution Build is a C++/ATL enhanced version of the VBScript Fast Project Build macro. It demonstrates many add-in concepts learned while developing the Workspace Whiz add-in for Visual Studio .NET. Most importantly, it illustrates the steps I have discovered to solidly run an add-in.
First, Fast Solution Build is fully capable of installing and uninstalling
itself through just a regsvr32
call. It is far more
convenient, especially when debugging, not to run an installer for add-in
installations and uninstallations. In AddIn.cpp,
DllRegisterServer()
handles registering the server and hooking up the
add-in's registry entries. The critical registry keys are at
HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\7.0\AddIns\FastSolutionBuild.Connect
and HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\7.0\PreloadAddinState.
The PreloadAddinState key tells Visual Studio .NET to force
creation of the add-in commands. Usually, VS.NET caches the add-in
commands and toolbar entries. Unfortunately, it doesn't do a very good job
of it and often loses the settings for them.
DllUnregisterServer()
illustrates a couple of important functions.
First, the add-in registry keys are removed, including GUIDs, typelibs, etc.
Finally, Fast Solution Build actually connects with the VS.NET COM object and
removes its registered commands. If the add-in created a toolbar (Fast
Solution Build just adds commands to the Tools menu), this is an appropriate
place to remove the toolbar, too.
The CConnect::OnConnection()
code is quite a bit different from
the boilerplate AppWizard generated code. It performs the following steps:
m_pDTE
andm_pAddInInstance
are set toNULL
. While developing Workspace Whiz, VS.NET called theOnConnection()
function more than once without callingOnDisconnection()
. Setting these values toNULL
ensures doubleOnConnection()
calls don't crash.- A test is made to see if this was launched from the command-line. This doesn't work for all command-line cases, but it covers some of them.
- During the execution of the function, large blocks of code are wrapped in
try-catch blocks. When launching from a command-line build, requesting
the
CommandBars
object, for instance, results in Visual Studio throwing an exception, instead of returning a proper error code. A similar thing happens when trying to add a named command to theCommands
object. Even though you can successfully retrieve theCommands
object, calledAddNamedCommand()
also causes Visual Studio to throw an exception. - The Tools menu is scanned for the presence of Fast Solution Build
commands. If they aren't there, it recreates them. Some VS .NET
crashes don't save out command icon information and don't bother calling
OnConnection()
again with aConnectMode
of5
(which causes recreation of the toolbar items and add-in commands). This check force recreates the commands, making the assumption they aren't there. - Again, in Workspace Whiz, cases were seen where events weren't properly
unregistered, due to
OnDisconnection()
not being called. Whole VS.NET crashes would result. Fast Solution Build unregisters the event handlers before it registers them.
Fast Solution Build implements two commands, BuildActiveProject
and RunActiveProject
. CConnect::Exec()
identifies the proper command and routes accordingly.
BuildActiveProject
works by performing the following steps:
- If the application is currently being debugged, a dialog box pops up
asking the user if they want to stop debugging. If the answer is no,
BuildActiveProject
exits. - Like VC6, all files are saved before the build.
- The Build output window pane is obtained through the function
GetOutputWindowPane()
. It is cleared and some text is displayed. - If any of the solution, solution build, build dependency, or other
EnvDTE
objects can't be retrieved,BuildActiveProject
exits with an error. - The startup projects are obtained. The startup projects are attached
to a
CComSafeArray
. If you attach aSAFEARRAY
to aCComSafeArray
and don't intend it to be destroyed, be sure to detach it orCComSafeArray
will destroy it! - All the dependencies begin to recurse.
- Any project that is not a C/C++ project is ignored.
- The solution context's "should build project" setting is used to ignore any projects the developer turned off for the solution configuration.
- All required dependencies are traversed. If they haven't been dependency checked yet, it goes back to step 6.
- The proper configuration and platform is retrieved for the project's context.
- If any of the children dependencies built, then a build is automatically forced for the parent projects.
- Finally, the
VCConfiguration.UpToDate
property is obtained. This is truly where all the magic happens. It seems as if theBuild Solution
command ignores theUpToDate
property and callsBuild
all the time. In fact, without the check forUpToDate
in Fast Solution Build, the macro behaves no different thanBuild Solution
!
RunActiveProject
expands on BuildActiveProject
by
doing the following extra items:
- If the debugger is active, no solution build will be performed.
However, the command
Debug.Start
is fired, to simulate theDebug
menu'sContinue
behavior when stepping or at a breakpoint. - The active project and all its updated dependencies are built.
Finally, Fast Solution Build wedges itself into a couple of BuildEvents.
When OnBuildProjConfigDone
is triggered, Fast Solution Build checks
for any errors during the current project's build. If it finds any, it
aborts the rest of the build through the Build.Cancel
command.
When OnBuildDone
is triggered and no build errors occurred,
Debug.Start
is called, causing the debugger to become active.
Known Bugs
- None at this time.
Conclusion
Please report any comments, bugs, or fixes to jjensen@workspacewhiz.com - thanks.
Edit History
4 Dec 2002 - Initial Edit
5 Dec 2002 - Version 2.01
- Made command-line builds not crash under certain circumstances.
- Stopped a secondary build from overriding a build already in progress.