简体   繁体   English

将.exe打包到.vsix中,然后从Visual Studio扩展中调用

[英]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. 我有一个Visual Studio包,它通过启动一个外部进程(使用System.Diagnostics.Process )并通过标准输入/输出与其通信来完成其某些工作。 Currently, I have the path to the .exe hard-coded which is obviously not workable for actually deploying the extension. 目前,我有.exe硬编码的路径,这对于实际部署扩展名显然不可行。 What is the right way to package and distribute the .exe with the extension? 用扩展名打包和分发.exe的正确方法是什么? (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. (并且,相关的,一旦完成,如何以编程方式发现安装的.exe文件的路径。)最好将其放入.vsix文件中,以便安装。

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. 编辑:我将代码的相关部分放在BitBucket上(它可能对使用Roslyn的其他人有用): roslyn_process ,以便更好地了解我要做什么。 This code sets up communication between a Visual Studio extension using an implementation of AbstractProcessHandler and a separate process using RoslynProcess . 此代码在使用AbstractProcessHandler的实现的Visual Studio扩展与使用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. 后者会随时了解有关Visual Studio中代码文件的修改以及正在查看哪个代码文件的信息,因此尽管未作为Visual Studio扩展运行,但它仍可以使用最新信息进行分析,这会带来以下限制: Roslyn在所有正在编辑的代码上。

EDIT 2: Using this answer , I can get the directory of the extension. 编辑2:使用此答案 ,我可以获取扩展名的目录。 I can include another package in source.extension.vsixmanifest by adding it to the content list as type "Custom Extension Type". 我可以通过将其作为“自定义扩展类型”类型添加到内容列表中来在source.extension.vsixmanifest包含另一个包。 Then the .exe appears in the extension's directory. 然后, .exe出现在扩展名的目录中。 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. 尽管在MSDN中将获取目录的方式标记为我不应该使用的方式,但这似乎似乎是正确的解决方案。

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. 即使看起来似乎有点骇人听闻,这似乎也是执行此操作的最佳方法,在这种情况下,一旦一切正常,我将把它作为答案发布。

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. 最简单的方法之一是让您的程序包DLL具有对EXE的项目引用,并使您的入口点类(或EXE中的某些类)公开。 Then you can just write: 然后,您可以编写:

typeof(ExternalProcess).Assembly.Location

which gives you the path to the EXE inside your extension path. 这为您提供了扩展路径中EXE的路径。

The other nice part about this is the VSIX packager should include the EXE into the VSIX automatically since it's a project reference. 另一个很好的方面是VSIX打包程序应该将EXE自动包含在VSIX中,因为它是项目参考。 You don't have to put anything at all in your .vsixmanifest for the EXE. 您无需在EXE的.vsixmanifest中放置任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM