Just another quick tip today. I wanted to create a Runspace to run some PowerShell code from C#. When I launched Visual Studio, and tried referencing PowerShell, which lives in System.Management.Automation, all I got was red wiggly underline. Similarly, the PowerShell object was not recognized.
To teach Visual Studio about the System.Management.Automation namespace, I needed to add the relevant DLL, which in my case (as I have x64 Windows 8.1) was found here:
"%ProgramFiles(x86)%\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll"
Once I add it to the References, wigglies go away and I can now use all the namespace has to offer:
Oh, if you are already in PowerShell console, you can see the current assembly location using this:
D:\> [psobject].assembly |flCodeBase : file:///D:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Management.Automation/v4.0_3.0.0.0__31bf3856ad364e35/System.Management.Automation.dllEntryPoint :EscapedCodeBase : file:///D:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Management.Automation/v4.0_3.0.0.0__31bf3856ad364e35/System.Management.Automation.dllFullName : System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35GlobalAssemblyCache : TrueHostContext : 0ImageFileMachine :ImageRuntimeVersion : v4.0.30319Location : D:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dllManifestModule : System.Management.Automation.dllMetadataToken :PortableExecutableKind :ReflectionOnly : False
No comments:
Post a Comment