如何配置我的安装项目以在安装过程中将程序集添加到 GAC?
首先,我知道为什么它没有出现在“添加引用”对话框中。我也知道如何手动添加它。
我想知道的是我应该如何更改我的安装项目(在 Visual Studio 中),以便程序集出现在“添加引用”对话框中。我应该添加新的目标位置、自定义操作还是其他内容?
我目前只是将“主要输出”放入“全局程序集缓存文件夹”中
First of all, I'm aware of why it doesn't appear in the "Add References" dialog. I also know how I can manually add it.
What I want to know is how I should change my Setup Project (in Visual Studio) so that the assembly appear in "Add reference" dialog. Should I add a new target location or a custom action or something else?
I currently just put the "Primary Output" in the "Global Assembly Cache Folder"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以修改安装项目以在安装时创建必要的注册表项并在卸载时删除它们。
请注意,理想情况下,您还需要将程序集部署到“正确的”安装文件夹,然后使用该部署文件夹作为 AssemblyReferences 项的目标文件夹 - 与 Microsoft 为其组件部署 Reference Assemblies 文件夹的方式相同。
更新
这是我为您准备的演示 VS2010 解决方案的链接: https://docs.google.com/leaf?id=0Bw_NnV9fhgmgNGE0N2JjYWYtNmVlNC00YjZhLWJlMGMtMDAyMTllYzU4Y2Fi&hl=en&authkey=CPTv8bUI 它将完全按照您的要求进行操作。
构建并运行安装项目后,“AddReferenceDemo”程序集将出现在“添加引用”对话框的“Assemblies\Extensions”选项卡中。
以下是我构建它的方法:
将主要输出添加到文件系统视图中的“应用程序文件夹”。
将主要输出添加到“全局程序集缓存文件夹”特殊文件夹(可选 - 仅当您也希望 GAC 中的文件时)
在注册表查看器中添加键 <使用 UI(您必须创建每一个)。这里的
[ProductName]
应该逐字使用,因为它是安装项目属性中设置的任何产品名称的快捷方式。在该值下添加一个默认字符串值(即无名称),其值为
[TARGETDIR]
- 再次逐字复制。请注意,这最终将设置为用户运行安装程序时选择的安装文件夹。构建并运行安装程序。
而且,即使您将其标记为这样,新的注册表项也不会在卸载时曾经被删除。可能该值也需要标记为删除。
请注意,安装程序应标记为“x86”目标平台,以便根据目标平台的位数使用正确的注册表节点(Software 或 Software\Wow6432Node)。如果您正在部署 x64 程序集,这并不重要 - 这是您在此处设置的安装程序的位数,它会影响注册表等的视图。
希望有所帮助。
You modify the setup project to create the necessary registry keys on installation and remove them on uninstallation.
Note that you ideally need to be deploying the assemblies to a 'proper' installation folder as well, and then use that deployment folder as the target folder for the AssemblyReferences key - in the same way that Microsoft deploys the Reference Assemblies folders for its components.
Update
Here's a link to a demonstration VS2010 solution I have prepared for you: https://docs.google.com/leaf?id=0Bw_NnV9fhgmgNGE0N2JjYWYtNmVlNC00YjZhLWJlMGMtMDAyMTllYzU4Y2Fi&hl=en&authkey=CPTv8bUI which will do exactly what you want.
After building and running the installation project the 'AddReferenceDemo' assembly will appear in the 'Assemblies\Extensions' tab of the Add Reference Dialog.
Here's how I built it:
Add primary output to 'Application Folder' in File System view.
Add primary output to 'Global Assembly Cache Folder' special folder (optional - only if you want the file in the GAC as well)
In the Registry viewer add the keys
Software\Microsoft\.NetFramework\v4.0.30319\AssemblyFoldersEx\[ProductName]
using the UI (you have to create each one). The[ProductName]
here should be used verbatim as it's a shortcut for whatever the product name is set in setup project's properties.Add a default string value under that (i.e. no name) with the value
[TARGETDIR]
- again copied verbatim. Note that this will ultimately be set to whichever installation folder the user chooses when they run your installer.Build and run the installer.
Also it doesn't appear the the new registry entry is ever deleted on uninstall, even if you mark it as such. Possibly the value needs to be marked for deletion as well.
Note that the installer should be marked as 'x86' target platform so that the correct Registry node (Software or Software\Wow6432Node) is used depending on the bitness of the target platform. It doesn't matter if you're deploying x64 assemblies - it's bitness of the installer that you're setting here and it affects the view of the registry etc.
Hope that helps.
添加引用对话框(无论是原始对话框还是 Productivity Power Tools 中的增强对话框)不会在 GAC 中搜索程序集。
相反,它会搜索在注册表中的几个位置之一指定的文件夹(取决于 .NET 框架版本和配置文件)。
例如。
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0\AssemblyFoldersEx
但是我认为搜索哪些文件夹的规则没有明确定义,因此可能需要一些尝试和错误。
The add references dialog (whether the original one or the enhanced one from Productivity Power Tools) does not search the GAC for assemblies.
Rather it searches the folders specified in one of several places in the registry (depending on .NET framework version and profile).
Eg.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0\AssemblyFoldersEx
However I don't think the rules about what folders are searched are clearly defined, so some trial and error may be needed.