MSBuild Context Menu Revisited

posted @ Saturday, September 10, 2005 10:37 AM

 

I mentioned in a previous post how to add a context menu for invoking MSBuild against any .*proj file. The only problem I had was I wasn't able to pass the file name to MSBuild, which would have typically been qualified with "%1" following the MSBuild command. When MSBuild is invoked and a file isn't passed to it, it searches the directory to find one. The problem is, if there are more than one .*proj files in the same directory, it doesn't know which file to run. To solve this, I moved the setting of the environment variables to the AutoRun key of the command prompt, this way, the environment variables are always set. Then I only had to invoke MSBuild from my command entry in which I was able to pass the selected file. Here are the two registry entries needed.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"AutoRun"="\"%VS80COMNTOOLS%vsvars32.bat\""
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Run with MSBuild\command]
@="cmd /k msbuild \"%1\""