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?