简体   繁体   English

为自定义工具包装.exe的便宜方法?

[英]Cheap way to wrap .exe for Custom Tool?

I have a custom script language and a compiler (an EXE written in C) that turns that language in to C# code. 我有一个自定义脚本语言和一个编译器(用C编写的EXE),可以将该语言转换为C#代码。 I'd like to hook up the script compiler as a Custom Tool on script files in the solution, and have it generate C# code behind. 我想将脚本编译器作为自定义工具挂接到解决方案中的脚本文件上,并在其后生成C#代码。

I've seen articles and tutorials online , and they all have you generate COM interfaces and register your custom DLL with the registry and GAC, and I really don't want to deal with all that. 我在网上看过文章和教程 ,它们都让您生成COM接口并向注册表和GAC注册您的自定义DLL,我真的不想处理所有这些。

Is there a wrapper or hack or 3rd party plugin somewhere that would make this easier? 是否有包装器,黑客程序或第三方插件可以简化此过程? Like if there was a way to run a batch script as the custom tool, and have the code behind file get generated from the stdout of that, I could pipe the file from my compiler to stdout. 就像有一种方法可以将批处理脚本作为自定义工具运行,并从该文件的stdout生成文件背后的代码一样,我可以将文件从编译器传递到stdout。

First off, I know you said you don't want to register through the MSFT way, but I suggest you reconsider. 首先,我知道您说过您不想通过MSFT方式进行注册,但是我建议您重新考虑。 Details are here: http://msdn.microsoft.com/en-us/library/vstudio/bb166527.aspx 详细信息在这里: http : //msdn.microsoft.com/zh-cn/library/vstudio/bb166527.aspx

Now that we got that out of the way, my suggestion to you: 现在我们解决了这个问题,我对您的建议是:

  1. Put your exe in a fixed location (best spot is probably right in the root of your solution or repository). 将您的exe放在固定位置(最佳位置可能就在解决方案或存储库的根目录中)。 Next, run your tool manually once, this way you have the .cs files or whatever you are generating so you can add them to your solution. 接下来,手动运行工具一次,这样您就可以拥有.cs文件或所生成的文件,以便将其添加到解决方案中。 That way the C# compiler knows they are there and you just have to hit the build button and it'll have the files to build. 这样,C#编译器就知道它们在那里,您只需要点击build按钮,它将拥有要构建的文件。

  2. Next, create a pre-build event (under project properties, build events tab) that calls your exe with the appropriate command line arguments to make it do its thing (generate your new cs files). 接下来,创建一个预构建事件(在项目属性下的“构建事件”选项卡下),该事件使用适当的命令行参数调用您的exe以使其执行其任务(生成新的CS文件)。 I suggest you edit your exe to take multiple files at a time, to make your pre-build command more simple. 建议您编辑exe一次获取多个文件,以使构建前命令更简单。 (This is where placing your file in the sln or repo directory is helpful, because you can use VS macros to get an absolute path to both your exe and the files to read in.) (在这里将文件放在sln或repo目录中会很有帮助,因为您可以使用VS宏获取exe和要读入的文件的绝对路径。)

  3. What happens now, is before msbuild gets called (but after you hit build) your script (or exe) will run to generate new output files. 现在发生的事情是在调用msbuild之前(但在您按下build之后),脚本(或exe)将运行以生成新的输出文件。 Since msbuild hasn't started yet you can change any solution files to your hearts content and the changes will be picked up by both msbuild and eventually (probably once the build is complete) VS. 由于msbuild尚未启动,因此您可以根据自己的喜好更改任何解决方案文件,并且这些更改将由msbuild以及最终(可能在构建完成后)VS进行。

Notes: I have never been able to get a build event to work on the first try, it usually throws an error that will show up in the VS error/warnings window. 注意:第一次尝试时,我始终无法获得构建事件的作用,它通常会引发一个错误,该错误将显示在VS错误/警告窗口中。 I usually copy the whole error into notepad (or scite) and edit it down to the actual command line with arguments. 我通常将整个错误复制到记事本(或scite)中,并使用参数将其编辑为实际的命令行。 I then open up a command shell and try to execute it. 然后,我打开命令外壳并尝试执行它。 The errors here are usually more helpful and you can tweak until you get it right and copy the changes back in to VS. 这里的错误通常更有用,您可以进行调整,直到正确无误,然后将更改复制回VS。

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

相关问题 自定义xsd.exe工具和区分大小写的xml序列化 - Custom xsd.exe tool and case sensitive xml serialization 有没有办法在VS Debugger中自定义自定义对象的工具提示? - Is there a way to customize the tool tip of a custom object in the VS Debugger? 在列表中每隔x%的时间来更新屏幕的计算便宜的方法是什么 - What is a computationally cheap way to update the screen every x% of the way through a list 有一种“便宜而简单”的方法来判断一个对象是否为特定类型实现了显式/隐式转换运算符? - Is there a “cheap and easy” way to tell if an object implements an explicit/implicit cast operator to a particular type? 在需要 char* 参数的应用程序组件之间传递更改 c++ 字符串的廉价且简单的方法 - cheap and easy way to pass changing c++ strings between components of an application expecting char* parameters DEVCON.EXE(驱动程序工具)和OpenVPN - DEVCON.EXE (driver tool) and OpenVPN 导出带有自定义图标的 exe - Exporting exe with custom icon 将属性包裹在自定义属性中 - Wrap attribute inside a custom attribute 有没有办法将对象包装为ConcurrentObject? - Is there a way to wrap an object up as a ConcurrentObject? 在委托声明中包装功能的方法 - Way to wrap functionality with in delegate declaration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM