Referencing System.Management.Automation.dll in a correct, multi-OS friendly way

醉酒当歌 提交于 2019-12-21 20:37:37

问题


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:

  • I always have to reference it with a full path (even though it’s in the GAC?)
  • The path is different on different OSs

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?


回答1:


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.



来源:https://stackoverflow.com/questions/11656296/referencing-system-management-automation-dll-in-a-correct-multi-os-friendly-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!