COM 注册和 GAC

发布于 2024-07-07 07:47:52 字数 496 浏览 6 评论 0原文

我在 Visual Studio 2005 中有一个 Web 项目、一个 C# 库项目和一个 Web 设置项目。Web 项目需要 C# 库需要在 GAC 中注册。 这很简单,只需将 GAC 文件夹添加到安装项目并将 C# 库的主要输出放入其中即可。 C# 库还需要注册 COM 互操作。 我单击选择 GAC 文件夹中的主输出,并将 Register 属性更改为 vsdrpCOM。 我构建了安装项目并运行它,但 DLL 从未注册到 COM。

这对我来说并不意外。 我总是必须添加一个安装程序类,该类具有一个自定义操作,该操作使用 RegistrationServices.RegisterAssembly 来正确注册 COM 的 DLL。 因此,我将多年来接受的这个解决方法应用于我的情况。 现在,我发现分配给安装项目的 GAC 文件夹中的主要输出的自定义操作甚至会阻止安装项目的构建。

我一直觉得我正在破解这些东西,让 .NET 和 COM 能够很好地处理设置和部署项目。 解决我的问题的正确方法是什么?

I have a web project, a C# library project, and a web setup project in Visual Studio 2005. The web project needs the C# library needs to be registered in the GAC. This is simple, just add the GAC folder to the setup project and drop the primary output of the C# library in there. The C# library also needs to be registered for COM interop. I click select the primary output in the GAC folder and change the Register property to vsdrpCOM. I build the setup project and run it but the DLL never gets registered for COM.

This is not really a surprise to me. I have always had to add an installer class which had a custom action which used RegistrationServices.RegisterAssembly to properly register my DLLs for COM. So I apply this workaround which I have accepted for years to my situation. Now I find that custom actions assigned to primary output in the GAC folder of a setup project prevent the setup project from even building.

I have always felt like I was hacking thigs to get .NET and COM to play nice with setup and deployment projects. What is the proper way to solve my problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡墨 2024-07-14 07:47:52

要使用 COM 注册程序集,请使用:regasm /codebase。 请参阅:http://msdn.microsoft.com/en- us/library/tzat5yw6(VS.80).aspx 了解详细信息。 我觉得你安装到 GAC 的方法很好。

To register the assemblies with COM use: regasm /codebase. See: http://msdn.microsoft.com/en-us/library/tzat5yw6(VS.80).aspx for details. Your method for installing into the GAC seems fine to me.

挽心 2024-07-14 07:47:52

WIX,将允许您轻松地在 GAC 中安装 COm 对象和程序集

WIX

WIX, will allow you to install your COm objects and assemblies in the GAC with little fuss

WIX

勿忘初心 2024-07-14 07:47:52

我不知道“正确”的方法,但我的团队通过批处理文件解决了这个问题。 我们将该文件称为“cycleCOM.bat”,并在构建后需要更新 GAC 和组件服务时运行它。 (我个人使用键盘启动器,因此我可以通过几次按键来触发此操作)

这是批处理文件的超级简化视图:

REM Unregister anything currently in component services

RemoveCom+.vbs

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regsvcs /u "C:\source\bin\FooCode.dll"

REM Remove from GAC

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" /uf FooCode

REM Register in component services

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regsvcs "C:\source\bin\FooCode.dll"

REM Add to GAC

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" /if "C:\source\bin\FooCode.dll"

RemoveCom+.vbs 文件会关闭组件服务中运行的任何内容。 它的代码是:

set cat = CreateObject ("COMAdmin.COMAdminCatalog")
Set apps = cat.GetCollection("Applications")

bFound = false
apps.Populate

lNumApps = apps.Count

' Enumerate through applications looking for AppName.
Dim app
For I = lNumApps - 1 to 0 step -1
    Set app = apps.Item(I)
    If app.Name = "FooCode" Then
      cat.ShutdownApplication ("FooCode")
      apps.Remove(I)
      apps.SaveChanges
    End If
Next

对于我们在本地处理的应用程序的每个版本,我们都有此脚本的多个版本,并且这些脚本可以轻松(嗯,尽可能简单)保持 GAC 和 COM+ 与版本同步正在编辑的代码。

I don't know about the "proper" way, but my team solves this issue with batch files. We call the file something like "cycleCOM.bat" and we run it after a build when we need to update the GAC and Component Services. (I personally use a keyboard launcher so I can trigger this with a few keypresses)

This is a super-simplified view of the batch file:

REM Unregister anything currently in component services

RemoveCom+.vbs

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regsvcs /u "C:\source\bin\FooCode.dll"

REM Remove from GAC

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" /uf FooCode

REM Register in component services

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regsvcs "C:\source\bin\FooCode.dll"

REM Add to GAC

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" /if "C:\source\bin\FooCode.dll"

The RemoveCom+.vbs file shuts down anything running in component services. Its code is:

set cat = CreateObject ("COMAdmin.COMAdminCatalog")
Set apps = cat.GetCollection("Applications")

bFound = false
apps.Populate

lNumApps = apps.Count

' Enumerate through applications looking for AppName.
Dim app
For I = lNumApps - 1 to 0 step -1
    Set app = apps.Item(I)
    If app.Name = "FooCode" Then
      cat.ShutdownApplication ("FooCode")
      apps.Remove(I)
      apps.SaveChanges
    End If
Next

We have multiple versions of this script for each version of our application that we work on locally, and the scripts make it easy (well, as easy as it can get) to keep the GAC and COM+ in sync with the version of code being edited.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文