Sunday, December 28, 2014

Adding Visual Studio Extensions into source control

The Problem

Extensions, are a very great way to add third party stuff into your Visual Studio, and your development environment, just like the Visual Studio NuGets, that provide you with great tools with just 2 clicks. This is extremely OK when you are working in a project on your own.
The real pain come when you are working on a project with a team, sharing code on a source control, or any way of files sharing. What typically happens is, someone on your team adds an extension into his Visual Studio, references the extension in a piece of code, and bom! compilation errors everywhere on everybody else's machines. So you have to ask everyone to install the right extension with the right version number that you decided to install. What makes it even worse is when you decide to install an update to the extension for some reason. This does really a huge mess, and wastes time for everybody trying to figure out what is breaking the build.
Unlike NuGets, Visual Studio has the option to automatically recover the missing NuGets when building the solution, extensions doesn't have this option, as it's not related to a project/solution but to the development environment and visual studio.

Solution - The Idea

To use an extension, all you have to do to reference the extension, is open the "Add Reference" dialog of a project, then select the Extensions from the left column, and you will get access to all the installed extensions in Visual Studio.
If you noticed when hovering over any of the extensions, you will find the location of the extension files,

The idea here, is to move the extension to a source controlled folder, and let the project file look for the extension in this folder, instead of the one installed in Program files folder. This will let everybody in your team get immediate access to the extension, the moment you check in the extension, and the project files. 

How To

In order to do this change, you should first copy the extension into your source controlled project folder, but not exactly a copy of the extension from the program files folder, but in a special folders' hierarchy. Next you have to do some changes into your project file to point to the new extensions folder.

Folder's structure

Create a folder, and name it "libs". Create the following nested folders as shown below, in the following order: Windows>v8.1>ExtensionSDKs>"SDKName">"SDKVersionNumber.

Now copy the extension contents from the default installation folder to the target folder under the SDKVersionNumber folder as shown below.

Project File Changes

Add the following lines at the end of the project file inside the Project main node:

Notice the highlighted part above, is the location of the "libs" folder that has your extensions, relative to your solution directory. You should change this as per your own reference. For instance, I have my libs folder in the same folder with my solution file, so I used $(SolutionDir)\libs.

If all the previous steps were done correctly, open the "Add References" dialog, and you will find duplicate entries of extensions in this list; one of the extension in its default install location, and the other in your newly created source controlled folder of your project. You will probably need to unselect the default location entry, and select the entry located in the newly folder.

No comments:

Post a Comment