我们正在开发一个引用一些 COM 库(例如 AutoIT)的 C# 应用程序.
We're developing a C# application that references a few COM libraries (AutoIT for example).
我将源代码控制下的所有引用组件包含在第 3 方Libs"文件夹中.
I am including all referenced components under source control, in a 3rd party "Libs" folder.
问题是 COM dll 在 .csproj 文件中没有 HintPath 属性,我假设这些必须使用 regsvr32(或使用某种脚本)手动注册.
The problem is that COM dll's don't have a HintPath property in the .csproj file, and i assume these must be manually registered using regsvr32 (or using a script of some sort).
我目前正在考虑创建一个将在每次构建之前运行的 MSBuild 脚本,但是我不知道是否应该手动调用 regsvr32.exe 或使用一些预定义的 MSBuild 任务?
I am currently looking into creating an MSBuild script that will run before every build, however i couldn't figure out if i should be manually calling regsvr32.exe or use some predefined MSBuild task?
目前,这是我尝试的测试:
Currently, this is what i've attmpted as a test:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<ItemGroup>
<MyAssemblies Include="D:*.dll" />
</ItemGroup>
<Target Name="Build">
<RegisterAssembly
Assemblies="@(MyAssemblies)" >
</RegisterAssembly>
</Target>
</Project>
这会产生错误,我放置在给定文件夹中的 DLL 不是有效的 DLL.
This generates errors that the DLLs i've placed in the given folder are not valid DLLs.
这个问题有什么好的解决方案?
What is a good solution for this problem?
引用 COM dll 的项目在 .csproj 文件中有类似的内容:
Projects that reference COM dlls have something similar to this in the .csproj file:
<COMReference Include="AutoItX3Lib">
<Guid>{F8937E53-D444-4E71-9275-35B64210CC3B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
这与其他托管程序集一样不包含任何提示路径,因此在构建服务器上,找不到引用的 COM dll.
This does not include any hint path as other managed assemblies, so on a build server, the referenced COM dll is not found.
使用 REGSVR32 在构建服务器上注册 COM dll 时,构建成功.
When registering the COM dll on the build server using REGSVR32, the build succeeds.
您没有在构建服务器上注册 COM 服务器.只有当您真正想要运行已编译的代码时,才需要这样做.您需要的是 COM 服务器的类型库,因此您可以获得互操作程序集.您使用 Tlbimp.exe 创建的.
You don't register COM servers on a build server. That's only required when you actually want to run the compiled code. What you need is the type libraries for the COM servers so you can get the interop assemblies. Which you create with Tlbimp.exe.
您是想在构建服务器上还是在开发机器上预先运行 Tlbimp,很大程度上取决于您如何部署这些 COM 服务器.将 COM 可执行文件和 .tlb 文件的副本保存在非常靠近您的互操作库的位置是一个好主意.换句话说,将它们签入.安装程序现在也可以检索已知良好的 COM 服务器版本.
Whether you want to run Tlbimp on the build server or up front on a dev machine depends a great deal on how you deploy these COM servers. Keeping a copy of the COM executables and .tlb files very close to your interop libraries is a good idea. In other words, check them in. The installer can now retrieve a known-good version of the COM server as well.
这篇关于在构建服务器上注册 COM 引用的 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!