Del via


How to add the Windows Powershell assembly / namespace in .NET

I thought it would be easy to create a PSSnapIn using .NET. But that wasn’t the case initially. When I first created a .NET project for creating a PSSnapIn and wanted to work with “Cmdlet” and “PSSnapIn”; I couldn’t add/find the assembly “System.Management.Automation” in my the project. Without this you can’t create your snap-in. The problem is still there and you can’t add this assembly in your project directly by choosing the add reference option.

So, the work around is to open the C# or VB.NET project file in notepad editor and add this line of code under the “<ItemGroup>” section. Save it and then again open in Visual Studio. You should be able to add the namespace “System.Management.Automation” now in your code file and can create the PSSnapIn.

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

Now, it was easy to create your customized snapin :)

Happy Programming!

Comments

  • Anonymous
    October 16, 2009
    Interesting, but why can't I choose the reference directly? And: Is System.Management.Automation.dll part of the PowerShell installation or is it part of the PowerShell SDK?

  • Anonymous
    October 16, 2011
    The comment has been removed