How can I configure my Setup Project to add an assembly to the GAC during the installation process?
First of all, I'm aware of why it doesn't 开发者_Python百科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"
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.
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.
精彩评论