在开发人员计算机上为 COM Interop DLL 编写 regasm 和 gacutil 脚本的好方法
我正在开发一个旨在在 VB6 项目中使用的 .NET 库。要设置要在我的开发人员计算机上使用的 dll,我使用 regasm
和 gacutil
,如下所示:
regasm /tlb:MyDll.tlb Mydll.dll
gacutil /i Mydll.dll
在每个后续调用中,我还取消注册/卸载程序集:
regasm /u /tlb:MyDll.tlb Mydll.dll
regasm /tlb:MyDll.tlb Mydll.dll
gacutil /u Mydll
gacutil /i Mydll.dll
目前,我正在这样做从 Visual Studio 工具命令提示符。有没有一种方法可以将这些命令编写到一个执行路径中?
注意:此脚本仅适用于我的 开发人员机器 其中 regasm
和 gacutil< /code> 两者都很容易获得。
I'm working on a .NET library that is intended to be consumed in a VB6 project. To set up the dll to be used on my developer machine, I use regasm
and gacutil
, like so:
regasm /tlb:MyDll.tlb Mydll.dll
gacutil /i Mydll.dll
On each subsequent call, I also unregister/uninstall the assembly:
regasm /u /tlb:MyDll.tlb Mydll.dll
regasm /tlb:MyDll.tlb Mydll.dll
gacutil /u Mydll
gacutil /i Mydll.dll
Currently, I'm doing this from the Visual Studio Tools command prompt. Is there a way to script these commands into one execution path?
NOTE: This script is intended only for my developer machine where regasm
and gacutil
are both readily available.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我最终如何自动化注册和 GAC 处理我的 dll 的过程。
首先,我在解决方案的根文件夹中创建了一个名为“ScriptedDevDellRegistration”的目录。我将最新版本的
gacutil.exe
和RegAsm.exe
(及其相应的 .config 文件)复制到此目录中。接下来,我在该目录中添加了一个名为
RegDll.cmd
的文件。该文件将使用其 tlb 注册 dll,然后将其安装到 GAC 中。当需要通过 COM 互操作在 VB6 开发环境中使用程序集时,这非常有用。该文件的内容是:我还添加了一个名为
UnGacDll.cmd
的文件,该文件将从 GAC 中卸载程序集。当运行使用不同项目中的程序集的控制台测试应用程序并且该程序集已添加到 GAC 时,我在调试工作时遇到了困难。该文件只是从 GAC 中删除 dll,以便我可以更轻松地进行调试:现在我已经设置了文件,我需要编辑项目的构建事件。
在正在编译和注册/GAC 的程序集的项目属性(我使用的是带有 VB.NET 的 VS2010)中,单击“编译”选项卡,然后单击“构建事件”按钮。在构建后事件中,添加类似于以下内容的代码:
cmd 脚本有点难看,但非常有用。我使用不同的构建配置来驱动在构建后事件中执行哪些脚本。例如,第一行查找名为“Release Scripted Dev Dll Registration”的构建配置,它将 DLL 复制到我创建的子目录中,然后执行 RegDll.cmd 来注册程序集及其类型库以及广汽集团的大会。
其他配置“调试控制台测试”和“调试控制台 Web 库”在 dll 不在 GAC 中时效果最佳,因此构建后事件会为这些配置调用
UnGacDll.cmd
。我确信可以在不物理复制 dll 或 regasm.exe 或 gacutil.exe 实用程序的情况下编写其中一些功能的脚本,但我上面解释的解决方案对我来说效果很好。
Here's how I ended up automating the process of registering and GAC-ing my dll.
First, I created a directory in the root folder of the solution called "ScriptedDevDellRegistration". I copied the most recent versions of
gacutil.exe
andRegAsm.exe
(with their corresponding .config files) into this directory.Next, I added a file into that directory called
RegDll.cmd
. This file will register the dll with its tlb and then install it in the GAC. This is useful when needing to consume an assembly in the VB6 development environment via COM interop. The file's contents are:I also added a file called
UnGacDll.cmd
that will uninstall the assembly from the GAC. When running a console test application that uses an assembly in a different project, and that assembly has been added to the GAC, I've had trouble getting debug to work. This file simply removes the dll from the GAC so that I can debug more easily:Now that I've got my files set up, I need to edit the Build Events of my project.
In the project's properties (I'm using VS2010 with VB.NET) for the assembly being compiled and registered/GAC'd, click the compile tab and click the "Build Events" button. In the post-build events, add code that is similar to the following:
The cmd scripting is kinda ugly, but very useful. I use different build configurations to drive which scripts get executed in the post-build events. For example, the first line looks for a build configuration named "Release Scripted Dev Dll Registration", which copies the DLL to the subdirectory I made and then executes
RegDll.cmd
to register the assembly and its type libraries as well as GAC the assembly.The other configurations, "Debug ConsoleTest" and "Debug Console Web Library," work best when the dll is not in the GAC, so the post-build event calls
UnGacDll.cmd
for those configurations.I'm sure it's possible to script some of this functionality without physically copying dll's or the regasm.exe or gacutil.exe utilities, but the solution I explained above worked well for me.