从 PowerShell 管理单元引用外部程序集

发布于 2024-08-07 03:12:12 字数 215 浏览 12 评论 0原文

我正在开发一个自定义 PowerShell 管理单元,它引用解决方案中的另一个项目。
当我尝试调试管理单元(按照[这些说明][1])时,程序集无法加载,并且我的 cmdlet 失败,并显示消息“无法加载文件或程序集...”

您如何指导 PowerShell 如何操作定位程序集,或者如何指定管理单元所需程序集的位置?

我宁愿避免在 GAC 中注册程序集,至少在开发期间是这样。

I'm developing a custom PowerShell snap-in, which references another project in the solution.
When I try to debug the snap-in (following [these instructions][1]), the assembly fails to load and my cmdlet fails with the message "Could not load file or Assembly..."

How do you instruct PowerShell on how to locate assemblies, or how do you specify where are located the assemblies needed by the snap-in?

I'd prefer to avoid registering the assemblies in the GAC, at least during development.

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

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

发布评论

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

评论(2

不即不离 2024-08-14 03:12:12

不确定确切的行为,但我会尝试使用 Fuslogvw 来准确查看运行时在哪里寻找有问题的程序集。这将为您提供有关如何将它们复制到构建时的正确位置的线索。 Scott Hanselman 的这篇文章是非常有用,这是官方的文档。

如果您找到解决方案,请添加答案,因为这一定是常见情况。

Not sure of the exact behaviour, but I would try and make use of fuslogvw to see exactly where the runtime is looking for the problematic assemblies. That would give you a clue as to how to get them to be copied into the correct place on build. This post by Scott Hanselman is quite useful, and this is the official documentation.

If you find the solution, please add an answer, as this must be a common scenario.

阪姬 2024-08-14 03:12:12

解决方案(按照我的问题的评论之一的建议将其发布到此处)

我的问题相当具体,因为我正在 64 位服务器计算机上进行开发,但我发布了解决方案,以防万一它也可以帮助别人。

按照建议使用 fuslogvw,我看到正在使用 C:\Windows\Microsoft.NET\Framework64machine.config 文件搜索依赖程序集code> 然后绑定失败;使用“启动而不调试”启动项目,而是获取 C:\Windows\Microsoft.NET\Framework 下的 machine.config 文件(注意缺少的 >64 位于末尾)。

我认为问题可能是由于图像格式造成的,事实上依赖程序集是使用 x86 作为 CPU 目标进行编译的;我将其更改为“任何 CPU”,现在程序集已正确加载。

SOLUTION (Posting it here as suggested by one of the comments to my question)

My problem was rather specific, as I'm developing on a 64 bits server machine, but I'm posting the solution in case it could help someone else as well.

Using fuslogvw as suggested, I saw that the dependent assembly was being searched using the machine.config file under C:\Windows\Microsoft.NET\Framework64 and then the binding failed; launching the project with "start without debugging", instead, the machine.config file under C:\Windows\Microsoft.NET\Framework was taken (notice the missing 64 at the end).

I thought that the problem could be due to the image format, and infact the dependent assembly was being compiled with x86 as CPU target; I changed it to "Any CPU" and now the assembly is loaded correctly.

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