Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package .exe into .vsix and call from Visual Studio extension

I have a Visual Studio package that does some of its work by starting an external process (using System.Diagnostics.Process) and communicating with it over standard input/output. Currently, I have the path to the .exe hard-coded which is obviously not workable for actually deploying the extension. What is the right way to package and distribute the .exe with the extension? (And, related, once I have done so, how do I programmatically discover the path to the installed .exe file.) Preferably I would like to put it into the .vsix file so installation is easy.

EDIT: I have placed the relevant part of my code on BitBucket (it may be useful to someone else using Roslyn): roslyn_process in order to give a better idea of what I am trying to do. This code sets up communication between a Visual Studio extension using an implementation of AbstractProcessHandler and a separate process using RoslynProcess. The latter is kept informed of modifications to the code files in Visual Studio and which code file is being viewed, so it is able to do analysis with up-to-date information despite not running as a Visual Studio extension which would impose the limitations of Roslyn on all code being edited.

EDIT 2: Using this answer, I can get the directory of the extension. I can include another package in source.extension.vsixmanifest by adding it to the content list as type "Custom Extension Type". Then the .exe appears in the extension's directory. This seems like it's probably the right solution although the way of getting the directory is labeled in MSDN as something I shouldn't be using.

It seems like this might be the best way to do this even though it seems hackish, in which case I'll post this as an answer once I get everything working.

like image 200
perelman Avatar asked Feb 08 '12 00:02

perelman


1 Answers

One of the simplest approaches to this is have your package DLL have a project reference to the EXE and make your entry point class (or some class within the EXE) be public. Then you can just write:

typeof(ExternalProcess).Assembly.Location

which gives you the path to the EXE inside your extension path.

The other nice part about this is the VSIX packager should include the EXE into the VSIX automatically since it's a project reference. You don't have to put anything at all in your .vsixmanifest for the EXE.

like image 195
Jason Malinowski Avatar answered Oct 25 '22 01:10

Jason Malinowski