I've looked this up and hunted around for vague descriptions enough times that I'm finally writing down how to programmatically install VSIX extensions using the VSIX installer.
Problems with Installing a VSIX Interactively
To install interactively a VSIX extension, you can simply execute the .vsix file from Windows Explorer or even the Command Window as well as using a Shell Commands for launching programmatically as .vsix is registered and automapped to the VSIXInstaller. Originally as part of an application I ship with a VSIX I simply used ShellExecute() to launch the installer.
This works, but it's very limited because:
- The VISX always launches interactively
- If the VSIX is already installed you get an error
- No way to uninstall other than through Visual Studio
Using the VSIXInstaller
If you want to install and uninstall a VSIX extensions programmatically as part of an install script, you can use the VSIXInstaller.exe that is installed into the Visual Studio IDE folder. This file lives in:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\VSIXInstaller.exe
and you can use it to both install and uninstall .vsix extensions with a bit more control than running the interactive installer.
Installing a VSIX is as easy as calling the installer with the full path to the .vsix file:
VSIXInstaller.exe /a "c:\webconnection\visualstudio\WebConnection-addin.vsix"
This simply runs the installation interactively bringing up the dialog and prompt from the user. If you'd rather just install the extension you can use the /q command switch which disables all prompts and simply installs.
The /a flag installs the VSIX in the admin area of Visual Studio - not quite sure what that means and I didn't see any real difference when I left it out – but all samples I've seen use it.
VSIXInstaller.exe /a /q "c:\webconnection\visualstudio\WebConnection-addin.vsix"
This does not solve the problem of updates however – if the extension is already installed, a new one is not automatically installed and the install fails. When the /q switch is a failure fails quietly.
Since you can't update with the install step and there's no explicit update option, you have to effectively uninstall and reinstall the add-in.
You can use the VSIX installer to uninstall an extension. In order to do this you need to know the Identifier which is a generated ID that gets stored in the VSIX manifest file. To find the identifier you can unzip your VSIX file (it's just a renamed .zip file) and look in the manifest file and there should be a Identifier key like this one:
<Identity Id="WebConnection_Addin.Rick Strahl.7c985797-3089-440a-a54c-b0125720263d"
Version="1.02.3" Language="en-US" Publisher="Rick Strahl" />
The ID is what you need as the identifier when you run the
vsixinstaller /q /a /u:"WebConnection_Addin.Rick Strahl.7c985797-3089-440a-a54c-b0125720263d"
BTW, if you want to see all the options of the VSIX installer just run it without a commandline which pops up a messagebox with option flags. The full syntax is:
VSIXInstaller.exe [/quiet] [/norepair] [/admin] [/skuName:name /skuVersion:version] [/logFile:filename] </uninstall:vsixID | vsix_path>
all command options shortcut by first letter. The key one are /q which disables all UI and quietly fails if it doesn't work which is great for scripted installs and /u to uninstall.
I'm not sure what the /admin switch does – I think it has something to do with where the extension registers. The main thing with this switch is be consistent in using the same switch for install and uninstall. Also not quite sure about the /norepair option which seems to indicate that if not specified will update the addin. I haven't seen this work – in my tests the installer always fails when installing and the add-in exists already.
Updating an Extension
So, since there is no update support how do you update an extension?
In my particular application users frequently update the application and as part of the installer I need to Update the Visual Studio Extension (an Add-in) I provide. As far as I can tell the VSIX installer doesn't allow for updates – it fails if the extension is already installed. So the only way to update an extension is to uninstall it then reinstall it. You can just run the two commands successively and allow some time inbetween. If you use the /q switch both install and uninstall process are pretty quick.
In my old application the install script does something like this:
lcVsVersion = "14.0"
IF (lcVersion > "2014")
lcinstaller = GetSpecialFolder(0x0026) + "Microsoft Visual Studio " + pcVsVersion + "\Common7\IDE\vsixinstaller.exe"
WAIT WINDOW "Uninstalling Visual Studio " + lcVsVersion + " Add-in..." nowait
CreateProcess(lcInstaller,[/q /a /u:"WebConnection_Addin.Rick Strahl.7c985797-3089-440a-a54c-b0125720263d"],,.T.,5000)
WAIT WINDOW "Installing Visual Studio " + pcVsVersion + " Add-in ..." nowait
CreateProcess(lcInstaller,[/q "] + FULLPATH("VisualStudio\WebConnection-Addin.vsix") + ["])
which uses options on CreateProcess to wait for completion of the process before running the next operation.
In .NET you can use Process.WaitForExit() to wait for Process completion before moving on:
var process = Process.Start(...);
Just as an aside, extensions installed end up the AppData Visual Studio configuration either in Local (as shown) or Roaming profile depending on how your network environment is set up. The folder is a random file name generated by the installer:
Note that you can effectively uninstall an extension simply by removing the folder which is kind of nice to know, but it might take a little sleuthing to find the right folder since the folder name doesn't match any id associated with your add-in.
Visual Studio's infrastructure remains a big pain when it comes to administering features. The biggest problem is a lack of decent documentation around this topic. But, it's getting better. I recently had to ugprade an old VS 2005 created add-in to the new VSIX model, and the process is loads and loads easier than it used to be – especially all the fanfare around hooking up menu options. But there's still a lot of ways to go to make add-ins easier to author and manage.
I hope this is helpful for some of you. I know I'll be referring back to this page frequently myself.
Other Posts you might also like