以正确的、多操作系统友好的方式引用 System.Management.Automation.dll [英] Referencing System.Management.Automation.dll in a correct, multi-OS friendly way

查看:65
本文介绍了以正确的、多操作系统友好的方式引用 System.Management.Automation.dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一段将调用 PS 脚本的 C#.作为其中的一部分,我引用了 System.Management.Automation.dll,PS 人员公开的库使我的生活更轻松.我认为这是使用正确的库(互联网搜索似乎可以确认,但如果我错了,请告诉我).此库作为 PS 安装/Windows SDK 的一部分进行安装.

I am writing a piece of C# that will invoke PS scripts. As part of this I’m referencing System.Management.Automation.dll, the library that the PS guys expose that makes my life easier. I assume this is the right library to use (internet searching seems to confirm but if I’m wrong let me know). This library is installed as part of the PS install / Windows SDK.

我发现这个库有两个奇怪的地方:

I’m finding two weird things about this library:

  • 我总是必须使用完整路径来引用它(即使它在GAC?)
  • 不同操作系统的路径不同

我在以下路径中找到了它(忽略了我认为不应该使用的 GAC 路径):

I’ve found it in the following paths (ignoring GAC paths which I assume I shouldn’t use):

  • win2k8 r2:C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0
  • Win7 x64:C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\

以多操作系统版本友好的方式引用此程序集的正确方法是什么?

What's the correct way to reference this assembly in a multi-OS-version friendly way?

推荐答案

SMA 程序集是体系结构中立的 (MSIL),因此将其复制到您的解决方案目录(或者可能是源结构中的 Imports 目录)并按路径引用该程序集从那个位置.这就是我们在 PowerShell 社区扩展 项目中所做的.

The S.M.A assembly is architecture neutral (MSIL) so copy one into your solution dir (or perhaps an Imports dir in your source structure) and reference the assembly by path from that location. That is what we do on the PowerShell Community Extensions project.

这篇关于以正确的、多操作系统友好的方式引用 System.Management.Automation.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆