title: How to reference System.Management.Automation in a .NET Framework 4.7.2?
body: <p>I started a new .NET Framework 4.7.2 library project.  I need to automate PowerShell scripts, but the "framework" tab in Visual Studio's reference adding UI didn't list System.Management.Automation as an option.  So I added a reference to this Nuget package:</p>
  
  <p><a href="https://www.nuget.org/packages/System.Management.Automation/7.0.0" rel="noreferrer">https://www.nuget.org/packages/System.Management.Automation/7.0.0</a></p>
  
  <p>Then with this code:</p>
  
  <pre><code>PowerShell ps = PowerShell.Create();
  ps.AddScript(@"C:\ps\function.ps1");
  ps.AddArgument(1);
  ps.AddArgument(2);
  Collection&lt;PSObject&gt; results = ps.Invoke&lt;PSObject&gt;();
  </code></pre>
  
  <p>I get this error about versions of a DLL which I did not directly reference:</p>
  
  <blockquote>
    <p>Assembly 'System.Management.Automation' with identity 'System.Management.Automation, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'System.Linq.Expressions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Linq.Expressions' with identity 'System.Linq.Expressions, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'</p>
  </blockquote>
  
  <p>I'm not sure how to resolve this, and I think maybe I approached adding my PowerShell automation library reference the wrong way.  What's the right way to do this currently?</p>
  
  <p>Before you point me at an old answer, I found a similar question about this which points to a different Nuget package, now marked "deprecated" and doesn't look official anyway.  That makes me nervous.</p>
  
  <p><a href="https://www.nuget.org/packages/System.Management.Automation.dll/" rel="noreferrer">https://www.nuget.org/packages/System.Management.Automation.dll/</a></p>