Often times, while working on SharePoint projects, I find myself needing to deploy only the code. I don't care about the Feature .xml files, or any of the other wonderfully useful files in a typical SharePoint project. Up until today, deploying this code was either a Solution upgrade, or launching a command file containing only the gacutil command along with an application pool recycle.
What prompted this post was that my current project contains multiple Visual Studio Solutions and each of those contain multiple Projects. Neither of the above two methods are very efficient since Solution upgrades take forever, and switching directories or having multiple command windows open at the same time is not manageable.
Visual Studio External Tool to the rescue!
You will need to create a command (cmd) file that contains the commands you want to launch using the External Tool. In my case, my file contained the commands listed below. Don't worry about %1 and %2, those are the arguments that will be supplied by the External Tool when we create it and are outlined below. Essentially, all this is doing is adding a folder to the PATH so that gacutill can be called, it's then calling gacutil to place the assembly into the GAC. The last line is recycling my application pool for my SharePoint site. This last line is optional. I needed it, you may not.
@set PATH=C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin;%PATH%
gacutil /i %1 /f
C:\WINDOWS\system32\cscript.exe C:\WINDOWS\system32\iisapp.vbs /a %2 /r
It needed to work across multiple projects and be contextually aware of the current project that I am working in so that it can deploy the assembly for that project. The solution was to create an External Tool to do this for me.
Under the Tools menu in Visual Studio, there is an External Tools... menu option. Clicking that gives you the External Tools dialog. Clicking on Add will add a new empty tool to the listbox.
Give the tool a tool a name, I named mine "Deplo&y Code Only". The ampersand in the name simply assigns a keyboard shortcut to this command (the best part in my opinion), as I will be able to launch this by simply clicking ALT-T-Y.
In the command textbox, enter the command you want to call. At first I was not sure that what I wanted to do was possible but after some experimenting, I found out that it was. What I mean here is that if you click on the buttons beside the Arguments or Initial Directory textboxes you will see that they bring up a list of possible macros you can use that provide dynamic references to places you care about, like the current project root folder, the current output path, etc... This button is not available next to the Command textbox. The macros ARE however usable in that textbox. My DeployCode.cmd is always at the root of my project but I don't want to have to create a new External Tool for every project. That would be silly. By using the $(ProjectDir) macro, I always get a reference to the root of my project.
In the Arguments textbox I am passing in the assembly path and the name of my application pool, since I am recycling it at the same time (this second argument is optional). The cool part here is that it will use the Debug or Release version of the assembly here depending on the Build Configuration you have selected in your project.
The Initial Directory textbox tells the External Tool to run in the project directory for the command. This is not required in this case.
I also checked the Use Output window checkbox so that I can see the output inside the Visual Studio environment.
This has made my life quite a bit easier since now it takes me about .5 seconds to deploy only the code for my project. I hope you find it as useful as I did.