views:

174

answers:

3

I have a build error in a c sharp program that I am compiling in Visual Studio 2008 on a Windows Server (2008, I guess) SP 2 64-BIT OS. It says that 'System.Management.Automation.PSObject' is defined in an assembly that is not referenced. I did some searching in MSDN and I found that this seems to be part of the Windows Power Shell SDK. http://msdn.microsoft.com/en-us/library/system.management.automation.psobject%28VS.85%29.aspx

The problem is that I already have the Windows Powershell. If this is all I need, how do I make use of it or reference it in the C Sharp IDE. If I need to download something extra (ie the SDK), where do I go to do this and install it? I could not find anything online.

+3  A: 

Look in C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0 for System.Management.Automation.dll and if it exists, add it as a reference in your C# project. If it doesn't exist, then download the Windows SDK which will put the file in the above location.

Keith Hill
Sweet.Thanks.That worked.
xarzu
+3  A: 

If you can't find it there, type this at a PowerShell prompt.

Copy ([PSObject].Assembly.Location) ~/Desktop
Josh Einstein
+1. Nice one :-)
Joey
Good Tip Too.Thanks.
xarzu
A: 

To correctly reference PowerShell, you should reference the PowerShell inside the GAC. The PowerShell included with the Vista SDK is PowerShell V1.0, and this technique will reference 1.0, 2.0, or X.0, whatever is installed. Referencing the SDK assembly will also not create the most portable of projects, because you have to have the SDK installed to build the project, rather than just Visual Studio and Windows.

Unfortunately, referencing GAC items is not something the visual studio UI does cleanly, so you have to go hand edit the CSProj file. Find the section with elements, and add this reference element.

<Reference Include="System.Management.Automation" />

This will reference the latest System.Management.Automation installed on the system, no matter what version it is.

Hope this helps

Start-Automating
Hmm, it is my understanding that the GAC is for runtime access to assemblies and that for compiling, you should put your assemblies in another location that can be easily referenced from Visual Studio e.g. "$env:ProgramFiles\Reference Assemblies".
Keith Hill
It really doesn't matter which one you reference. The strong name will match and publisher policy will redirect to the correct assembly in GAC no matter where you referenced it from. The one in GAC is just a last resort way to get an up to date assembly to reference. With SharePoint for example it's the only way to extract the assemblies for a client os to build against.
Josh Einstein
Well it used to be the case that you referenced in a location that also came with a XML doc comment file that provided extra Intellisense information. Not sure if that is still the case today.
Keith Hill