windows 使用 WiX 安装程序复制 Visual Studio COM 注册
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/543995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replicating Visual Studio COM registration with a WiX Installer
提问by Robert P
Once upon a time, a young, naive engineer thought it would be a good idea to separate out some of the functionality for his app into a COM component, written in C#. Visual studio had all the tools to do that, right? .NET was practically made for this, right? HA! He said, this will be easy. I'll have decent separation of components, keeping business logic away from the front end, and with COM, I'll be able to use it from anywhere! He merrily checked the register for COM interop
checkbox in the project properties, exposed the classses he wanted, and went on his way.
曾几何时,一位年轻、天真的工程师认为将他的应用程序的某些功能分离到一个用 C# 编写的 COM 组件中是个好主意。Visual Studio 拥有做到这一点的所有工具,对吗?.NET 实际上就是为此而生的,对吧?哈!他说,这会很容易。我将对组件进行适当的分离,使业务逻辑远离前端,并且使用 COM,我将能够从任何地方使用它!他兴高采烈地勾选了register for COM interop
项目属性中的复选框,暴露了他想要的类,然后继续他的工作。
Oh, the trials such a choice made. The young engineer now, more experienced, would not now wish this upon anyone. However, the burden had been placed upon his shoulders, and the burden remained heavy. He looked to lighten the load.
呵呵,试炼做出这样的选择。现在年轻的工程师更有经验,现在不会希望任何人都这样。然而,重担已经压在了他的肩上,重担依旧沉重。他想减轻负担。
Along came WiX, a tool for generating Windows Installer files from XML. This intrigued him - it could replicate, quite simply, most of the code needed for a proper windows installer file simply from a handful of configuration files. His sights were looking up.
随之而来的是 WiX,这是一种从 XML 生成 Windows Installer 文件的工具。这引起了他的兴趣 - 它可以简单地从少数配置文件中复制正确的 Windows 安装程序文件所需的大部分代码。他的视线在抬头。
With WiX 2.0, he could generate quite easily the files needed to register a C# COM object. This involved using the tool tallow. He'd do something like the following:
使用 WiX 2.0,他可以很容易地生成注册 C# COM 对象所需的文件。这涉及使用工具牛油。他会做如下事情:
tallow -c -nologo MyComExposedLibrary.dll > MyComExposedLibrary.wxs
which would then be fixed up (at first this was done manually, but eventually I recorded the steps into a small tool set the final directory ref id, component ID, fileID, GUID and codebase).
然后将其修复(起初这是手动完成的,但最终我将这些步骤记录到一个小工具中,设置了最终目录引用 ID、组件 ID、文件 ID、GUID 和代码库)。
Then, the ensuing installer would install, and there would be joyous celebration, if the app worked.
然后,随后的安装程序将安装,如果应用程序正常运行,将会有欢乐的庆祝活动。
Which it did not.
它没有。
For days the young engineer poured over the differences on his development PC and that of the test install PC. "All the registry keys are the same!" He would exclaim. "Everything for MyComExposedLibrary is registerd, I swear!"
几天来,这位年轻的工程师倾诉了他的开发 PC 和测试安装 PC 的差异。“所有的注册表项都是一样的!” 他会惊呼。“MyComExposedLibrary 的所有内容都已注册,我发誓!”
Except, it wasn't.
除了,它不是。
On the dawn of third day, after many a mountain dew, he realized there was one more object that Visual Studio was registering that his installer was not: the MyComExposedLibrary.tlb file.
在第三天的黎明,在经历了许多山露水之后,他意识到 Visual Studio 正在注册的另一个对象不是他的安装程序:MyComExposedLibrary.tlb 文件。
Visual Studio, apparently, had been registering this file all along, creating additional subkeys in the HKLM\Software\Classes\Interface
registry key, and registering the typelib in HKLM\SOFTWARE\Classes\TypeLib
.
显然,Visual Studio 一直在注册这个文件,在HKLM\Software\Classes\Interface
注册表项中创建额外的子项,并在HKLM\SOFTWARE\Classes\TypeLib
.
Tallow gave no help, complaining that a .tlb wasn't a file it groked. Nor the WiX 3.0 beta - this seemed to have even more issues getting things working.
Tallow 没有提供任何帮助,抱怨 .tlb 不是它所处理的文件。也不是 WiX 3.0 测试版——这似乎在让事情正常工作时遇到了更多问题。
I also gave Heat a try. This generated registry elements and class elements. I cleaned up heat's output, and then went to compile it, but got a different error: error LGHT0130 : The primary key <uuid here> is duplicated in table 'Registry'
. Problem is, as far as I can tell, that uuid doesn't actually exist in any of my wxs source files. If I change around the component ref order in my feature element, a different dll component gives that error. Since I have been unsuccessful at getting a WiX 3.0 version of the project to compile, I haven't been able to confirm whether or not heat gives the right output.
我也试了一下热火。这生成了注册表元素和类元素。我清理了 heat 的输出,然后去编译它,但得到了一个不同的错误:error LGHT0130 : The primary key <uuid here> is duplicated in table 'Registry'
. 问题是,据我所知,uuid 实际上并不存在于我的任何 wxs 源文件中。如果我更改功能元素中的组件引用顺序,则不同的 dll 组件会出现该错误。由于我未能成功编译项目的 WiX 3.0 版本,因此我无法确认 heat 是否提供了正确的输出。
I removed everything from the installer except for one of the assembly that cause this error to appear and tried compiling again. I got the same same error. Arrugh!
除了导致出现此错误的程序集之一,我从安装程序中删除了所有内容,然后再次尝试编译。我得到了同样的错误。啊!
So, my good fellows, Windows enthusiasts, and WiX users, there falls two questions:
所以,我的好伙伴、Windows 爱好者和 WiX 用户,有两个问题:
- Is a typelib something that WiX can register natively? If so, how?
- If not, what's the proper way of registering a typelib with a windows installer?
- 类型库是 WiX 可以本地注册的东西吗?如果是这样,如何?
- 如果没有,使用 Windows 安装程序注册 typelib 的正确方法是什么?
Also, I guess as another part of this, how does Visual Studio determine how to register the typelib? (Edit: looks the MSDN library article on typelib registration has the names of the keys needed, but I still need to figure out how to get the uuid's. (This is from this blog post on typelib and COM registration by Larry Osterman.) ) Reading a bit more, It may fall to me to register these bits manually, but I hope not...
另外,我想作为另一个部分,Visual Studio 如何确定如何注册 typelib?(编辑:看起来关于 typelib 注册的MSDN 库文章有所需键的名称,但我仍然需要弄清楚如何获取 uuid。(这是来自Larry Osterman 关于 typelib 和 COM 注册的这篇博客文章。))多读一点,我可能会手动注册这些位,但我希望不会......
I evaluated the output from regasm /regfile:MyDll.dll MyDll.dll
. It looks like these are the same keys that wix generates for the dll. Regasm's other mode, regasm /tlb:<filename>
generates and registers the typelib for the assembly, but,
我评估了regasm /regfile:MyDll.dll MyDll.dll
. 看起来这些密钥与 wix 为 dll 生成的密钥相同。Regasm 的另一种模式,regasm /tlb:<filename>
为程序集生成并注册类型库,但是,
/regfile[:FileName] Generate a reg file with the specified name instead of registering the types. This option cannot be used with the /u or /tlb options
/regfile[:FileName] 生成具有指定名称的 reg 文件,而不是注册类型。此选项不能与 /u 或 /tlb 选项一起使用
seems the /regfile switch is incompatible with the /tlb switch. Khaaaaaaaan!
似乎 /regfile 开关与 /tlb 开关不兼容。啊啊啊啊啊!
Further update:It looks like you don't actually needto include the .tlb file. According to this post on wix's typelib element, an MSI can create/register this as part of the setup process. It all comes down to configuring the WiX document to actually install it by getting the right attributes.
进一步更新:看起来您实际上并不需要包含 .tlb 文件。 根据 wix 的 typelib element 上的这篇文章,MSI 可以将其创建/注册为设置过程的一部分。这一切都归结为配置 WiX 文档以通过获取正确的属性来实际安装它。
I found out later that you can get the right attributes using heat on the .tlb directly! See this SO question for more information.
采纳答案by CheGueVerra
You should use Heat (WIX 3.0) located in the bin directory of the version you are using. Have a look at this blogpost, we use it here to register all our COM objects, by creating a wix fragment...
您应该使用位于您所使用版本的 bin 目录中的 Heat (WIX 3.0)。看看这篇博文,我们在这里使用它来注册我们所有的 COM 对象,通过创建一个 wix 片段......
something like
就像是
heat file MyComExposedLibrary.dll -out MyComExposedLibrary.wxs
After, reading your edit, I would create a basic msi with wix that installs the com object only, see if that works ... then you'll know which battlefield to attack ...
之后,阅读你的编辑,我会用 wix 创建一个基本的 msi,它只安装 com 对象,看看它是否有效......然后你就会知道要攻击哪个战场......
回答by hurcane
I recently ran into this issue, and the simplest workaround I could find follows these steps on the development machine:
我最近遇到了这个问题,我能找到的最简单的解决方法是在开发机器上遵循以下步骤:
- Run: Regasm MyDLL.dll /tlb:MyDLL.tlb
- Run: Heat file MyDLL.dll -out MyDll-1.wxs
- Run: Heat file MyDll.tlb -out MyDll-2.wxs
- 运行:Regasm MyDLL.dll /tlb:MyDLL.tlb
- 运行: Heat file MyDLL.dll -out MyDll-1.wxs
- 运行: Heat 文件 MyDll.tlb -out MyDll-2.wxs
MyDll-2.wxs contains a <Typelib>
element that you will want to copy and nest inside the <File>
element that was generated in MyDll-1.wxs. This will give you a complete <Component>
element that you can use in the installer project.
MyDll-2.wxs 包含一个<Typelib>
元素,您需要将其复制并嵌套<File>
在 MyDll-1.wxs 中生成的元素中。这将为您提供<Component>
可在安装程序项目中使用的完整元素。
回答by Wim Coenen
To extract the COM information, tallow will use the regasm.exe toolincluded with the .NET framework. It is likely that visual studio uses the same tool to register assemblies when you enable "register for COM interop".
为了提取 COM 信息,tallow 将使用.NET 框架中包含的regasm.exe 工具。当您启用“注册 COM 互操作”时,visual studio 很可能使用相同的工具来注册程序集。
The difference is that tallow will use the regasm /regfile switch to send the information to a .reg file instead of actually registering the assembly. Unfortunately the .reg file generated by regasm.exe is not complete. It skips the typelib entries which it does write to the registry during a real registration. This may be a bug in regasm.
不同之处在于 tallow 将使用 regasm /regfile 开关将信息发送到 .reg 文件,而不是实际注册程序集。不幸的是,由 regasm.exe 生成的 .reg 文件并不完整。它会跳过在实际注册期间写入注册表的 typelib 条目。这可能是 regasm 中的一个错误。
To get your installer working you have three options:
要让安装程序正常工作,您有三个选择:
Add the missing registry keys to the tallow output manually. The tallow output is intended to be edited manually and saved along with your other wxs files anyway. You seem to be trying to fully automatically generate a working wxs file but I believe that was never a design goal of tallow.
Use a custom actionto invoke regasm from your installer. This is slightly evil because you may lose some of the strong transactional guarantees provided by the windows installer engine. I'm thinking of rollbacks triggered by a failure halfway during the install here.
Avoid the registration altogether by making use of registration-free COM.This will require the creation of manifest files for both the application and the COM library.
回答by Dave
I know this is an older question, but others may find this useful...
我知道这是一个较老的问题,但其他人可能会发现这很有用......
After struggling with this myself, I found that you can capture the type library information by using tlbexp.exethen heat both the dll and the tlb file. Include the outputs of both of those in your wix project and you should be good to go.
在自己苦苦挣扎之后,我发现您可以通过使用tlbexp.exe捕获类型库信息,然后同时加热 dll 和 tlb 文件。在您的 wix 项目中包含这两个的输出,您应该很高兴。
tlbexp.exe dllFile.dll /out:dllFile.tlb
heat.exe dllFile.dll ...
heat.exe dllFile.tlb ...