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.

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();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s