简体   繁体   English

从C#打开C:\\ windows \\ assembly \\ gac_msil

[英]Open C:\windows\assembly\gac_msil from C#

How can I open C:\\windows\\assembly\\gac_msil in a Windows Explorer window using C#? 如何使用C#在Windows资源管理器窗口中打开C:\\windows\\assembly\\gac_msil

Explanation: When I deploy an assembly to the GAC in my development environment, I like deploying the .pdb symbol file to the same directory as the assembly located at C:\\Windows\\assembly\\GAC_MSIL\\AssemblyName\\Version__PublicKeyToken\\ . 说明:在我的开发环境中将程序集部署到GAC时,我喜欢将.pdb符号文件部署到与位于C:\\Windows\\assembly\\GAC_MSIL\\AssemblyName\\Version__PublicKeyToken\\的程序集相同的目录中。 That way if I want to attach the Visual Studio debugger, it automatically finds the symbol file. 这样,如果我想附加Visual Studio调试器,它会自动找到符号文件。

I've built a little utility that detects when I add one of my assemblies to the GAC and I want it to show a button that pops open the directory for me. 我已经构建了一个小实用程序来检测何时将我的一个程序集添加到GAC中,并且我希望它显示一个按钮,为我弹出打开目录。 I have the button and the path, but starting a process that launches explorer.exe with the path doesn't work. 我有按钮和路径,但启动一个启动explorer.exe与路径的进程不起作用。 The only way I know of to open this directory in Windows is through the Run dialog. 我知道在Windows中打开此目录的唯一方法是通过“运行”对话框。

You can't get to it within explorer or using the command line command: explorer.exe "C:\\Windows\\assembly\\GAC_MSIL..." . 您无法在资源管理器中或使用命令行命令访问它:explorer.exe "C:\\Windows\\assembly\\GAC_MSIL..." Only if you type the path into the Run dialog. 仅当您在“运行”对话框中键入路径时。 So how do I do what the Run dialog is doing? 那么我该怎么做Run对话框呢?

As Hans Passant at one time had answered, the old GAC is displayed by a shell extension which masks the directory structure. 正如Hans Passant曾经回答的那样,旧的GAC由一个shell扩展显示,它掩盖了目录结构。 This is to make sure the assemblies in the GAC are managed properly. 这是为了确保正确管理GAC中的程序集。 Opening the directory structure is intentionally not supported. 故意不支持打开目录结构。 In .NET 4, that is no longer the case so if you can upgrade, that's the way to go. 在.NET 4中,情况已经不再如此,所以如果你可以升级,那就是你要走的路。

To programmatically open the old GAC there are a few options but again, it is normally masked for a reason. 要以编程方式打开旧GAC,有一些选项,但同样,它通常会被掩盖是有原因的。 Options: 选项:

  1. Remove the shell extension. 删除shell扩展。 You can unregister Shfusion.dll, open the directory, then re-register it. 您可以取消注册Shfusion.dll,打开目录,然后重新注册。 This, of course, could go wrong and leave you with Shfusion.dll permanently unregistered. 当然,这可能会出错并让您将Shfusion.dll永久取消注册。 This would allow other users to freely mess with the GAC directory structure and files which would cause it to become invalid and fall out of sync with the registry = bad. 这将允许其他用户自由地处理GAC目录结构和文件,这将导致它变得无效并与registry = bad不同步。

  2. Disable the shell extension. 禁用shell扩展。 The HKLM Fusion registry key can have a DisableCacheViewer DWORD value. HKLM Fusion注册表项可以具有DisableCacheViewer DWORD值。 When set to 1, it will disable the view. 设置为1时,将禁用视图。 The key can be set to 1, the window opened, then the key can be set back to 0. This approach has the same risks as option 1. Additionally, as a user (Damien) whose comment seems to have been deleted pointed out, other processes may also use this global key causing a race condition = bad. 密钥可以设置为1,窗口打开,然后密钥可以设置回0.这种方法与选项1具有相同的风险。此外,作为用户(Damien)的评论似乎已被删除指出,其他进程也可能使用此全局密钥导致竞争条件=坏。

  3. Use a 3rd party application like Total Commander (thanks to Csaba Toth) or Far Manager to view the directory structure instead of Explorer. 使用Total Commander(感谢Csaba Toth)或远程管理器等第三方应用程序来查看目录结构而不是资源管理器。 The downside here is, assuming they can even accept arguments to allow them to open to the GAC directory, it would require installing that software everywhere I want to run my app. 这里的缺点是,假设他们甚至可以接受允许他们打开GAC目录的参数,那么需要在我想运行我的应用程序的任何地方安装该软件。

If you are considering using options 1 or 2, be aware that in most scenarios they are a bad idea and should be avoided unless you are messing around with your own machine. 如果您正在考虑使用选项1或2,请注意在大多数情况下它们都是一个坏主意,除非您正在使用自己的机器,否则应该避免使用它们。 This directory structure is synchronized with the registry and should not be directly edited. 此目录结构与注册表同步,不应直接编辑。 Use Gacutil.exe to manage the assemblies in the GAC. 使用Gacutil.exe管理GAC中的程序集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM