C#, XAML, and System.Management.Automation Reference

Do you get an error attempting to create a XAML app referencing System.Management.Automation (which you need for PowerShell much like is described as in this link)? You also tried adding it in via the Add>Reference… option from within the Solution Explorer which only seems to have System.Management?

It displays something like this:
XAML - Using directive is unnecessary
How to fix:

Install the NuGet package and reference it in your project.

Alternatively:
1 – Save your XAML Project and close it.
2 – Using your favorite text editor, open the <MyXAMLApp>.csproj file and add the reference manually with:

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

XAML - Editing XAMLApp.csproj
3 – Save and re-open your project. Boom! You can now create new instances:
PowerShell ps = PowerShell.Create();

Advertisements