Click here to Skip to main content
15,860,844 members
Articles / Programming Languages / C++
Article

Build Visual Studio .Net 2003 and 2005 solutions or projects by right clicking in Explorer

Rate me:
Please Sign up or sign in to vote.
4.00/5 (12 votes)
26 Jul 20062 min read 54.1K   581   23   10
Implementing a Windows Shell Extension to provide "Build Here" functionality

Build Here

Introduction

This article explains how to easily extend Windows shell functionality. By integrating your application with the Shell, you can extend the Shell's functionality and customize certain aspects of its behavior. In order of increasing complexity, you can extend the Shell by:

  • Putting information in the registry or in special files.
  • Implementing a Shell extension handler.
  • Implementing a namespace extension.

File associations use verbs as shorthand for actions that are invoked on items in the Shell namespace, including files and folders. Verbs are closely related to the Shell shortcut menus, where each menu item is associated with a verb.

Supplemental verbs are any verbs other than the standard canonical verbs, and are most often used to add custom behavior beyond what the default system verbs provide. On Windows XP or later, you can add supplemental verbs to the SystemFileAssociations extension, or to the Shell subkey for the PerceivedType key.

Using the code

For example, suppose CoolLogEditor is a text LOG editor and the developers of CoolTextEditor want to add a supplemental verb that displays "CoolLogEditor" when you right-click any file of the ".log" extension type To accomplish this, a key named CoolLogEditor is added to the registry as follows:

[HKEY_CLASSES_ROOT\SystemFileAssociations\.log\shell\CoolLogEditor\command]
@="CoolLogEditor.exe \"%1\"\"

For more information refer to the following MSDN articles

Here is how VS.Net BuildHere works

Following are registry keys which will add a menu item on the File Explorer. When you right click a Microsoft Visual Studio 2003 or 2005 Project or Solution a batch file find outs correct version of the Project or Solution and sets environment and runs compile command for it.

Registry Values for menu item "VS.Net BuildHere-Debug":
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\SystemFileAssociations\.sln\shell\
VS.Net BuildHere-Debug\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Debug.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.sln\shell\
VS.Net BuildHere-Release\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Release.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.csproj\shell\
VS.Net BuildHere-Debug\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Debug.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.csproj\shell\
VS.Net BuildHere-Release\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Release.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.vcproj\shell\
VS.Net BuildHere-Debug\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Debug.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.vcproj\shell\
VS.Net BuildHere-Release\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Release.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.vbproj\shell\
VS.Net BuildHere-Debug\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Debug.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.vbproj\shell\
VS.Net BuildHere-Release\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Release.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.vjsproj\shell\
VS.Net BuildHere-Debug\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Debug.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.vjsproj\shell\
VS.Net BuildHere-Release\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Release.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.vdproj\shell\
VS.Net BuildHere-Debug\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Debug.bat\" \"%1\"\""

[HKEY_CLASSES_ROOT\SystemFileAssociations\.vdproj\shell\
VS.Net BuildHere-Release\command]
@="cmd.exe /k \"\"[INSTALLDIR]\VS.Net BuildHere-Release.bat\" \"%1\"\""

Batch File (VS.Net BuildHere-Debug.bat):
@rem Author: Priyakant Patel
@rem http://www.priyakant.com

@prompt $S

@rem if ProductVersion starts with 8 then it is Microsoft Visual Studio 
@rem .Net 2005

@findstr "<.*ProductVersion.*>.*8.*</.*PRODUCTVERSION.*>" %1
@IF %ERRORLEVEL% LSS 1 goto LABEL_VS8

@rem if File Format Version starts with 9 then it is Microsoft Visual 
@Studio .Net 2005

@findstr ".*Format.*Version.*9" %1
@IF %ERRORLEVEL% LSS 1 goto LABEL_VS8

@findstr "#.*Visual.*Studio.*2005" %1
@IF %ERRORLEVEL% LSS 1 goto LABEL_VS8

:LABEL_VS7
@cls
@echo *** *** Project is a Microsoft Visual Studio .Net 2003 *** ***
Call "%VS71COMNTOOLS%vsvars32.bat"
@echo **** building following solution in ~~Debug~~ mode ****
@echo %1
@devenv %1 /rebuild Debug

@goto LABEL_END

:LABEL_VS8
@cls
@echo *** *** Project is a Microsoft Visual Studio .Net 2005 *** ***
Call "%VS80COMNTOOLS%vsvars32.bat"
@echo **** building following solution in ~~Debug~~ mode ****
@echo %1
@devenv %1 /rebuild Debug

@goto LABEL_END

@echo Before end
:LABEL_END
@echo Hit enter to exit
@pause
@exit

Conclusion

I hope you will enjoy this handy tool.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Sharjith28-Feb-12 6:44
professionalSharjith28-Feb-12 6:44 
GeneralMy vote of 2 Pin
vegaam24-Sep-09 21:13
vegaam24-Sep-09 21:13 
GeneralNot seeing anything when i right click Pin
srisan14-May-08 4:37
srisan14-May-08 4:37 
QuestionHow to insert a menu when right click blank place? Pin
hays.zhao6-Jun-07 21:36
hays.zhao6-Jun-07 21:36 
GeneralExtend Functionality Pin
Marco_Frigerio_13-Mar-07 6:52
Marco_Frigerio_13-Mar-07 6:52 
Generalerror question please Pin
erikkl200020-Oct-06 8:23
erikkl200020-Oct-06 8:23 
GeneralRe: error question please Pin
erikkl200020-Oct-06 9:44
erikkl200020-Oct-06 9:44 
GeneralRe: error question please Pin
Priyakant Patel3-Nov-06 8:46
Priyakant Patel3-Nov-06 8:46 
Questionwhy go to all that trouble, finding which version of the Pin
Chen Ganir26-Jul-06 17:46
Chen Ganir26-Jul-06 17:46 
AnswerRe: why go to all that trouble, finding which version of the Pin
Priyakant Patel27-Jul-06 5:34
Priyakant Patel27-Jul-06 5:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.