(Please re-open issue#7675)
dotnet new consoleTargetFramework to net461 even net471. netcoreapp is working. RuntimeIdentifier (2 different types of exception will be thrown) <RuntimeIdentifier>win-x64</RuntimeIdentifier>
namespace test
{
using System.Management.Automation;
internal class Program
{
private static void Main(string[] args)
{
PowerShell ps = PowerShell.Create();
Console.ReadKey();
}
}
}
The code could pass.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Management.Automation" Version="6.1.2" />
</ItemGroup>
</Project>
Throw exception:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Management.Automation, Version=6.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.'

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net471</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Management.Automation" Version="6.1.2" />
</ItemGroup>
</Project>
Throw exception:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

OS: Windows 10
Visual studio: Visual studio 2017 5.9.5
I check the nuget package System.Management.Automation with NuGet package Explore

Here are the problems:
RuntimeIdentifier is assigned. We can see from the screen shot that: the System.Runtime 4.2.1.0 is in referenced assemblies of the System.Management.Automation.dll(double click the file in Nuget Package Explorer). Maybe most of the referenced assemblies(dependencies) are in the Netframework binaries. But when we add the System.Runtime reference manualy we could see: The version of it is 4.1.2.0.
Please see comment in #4669.
Please see comment in #4669.
Hi @iSazonov. I have tried to use the package Microsoft.Powershell.SDK, Microsoft.PowerShell.Commands.Diagnostics, Microsoft.WSMan.Management. Still not work. Here is the csproj.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.PowerShell.Commands.Diagnostics" Version="6.1.2" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.1.2" />
<PackageReference Include="Microsoft.WSMan.Management" Version="6.1.2" />
</ItemGroup>
</Project>
I think I have the different case. Because I am using NET FRAMEWORK as target. It is working if I change the target framework to netcore. BUT that is not what I want.
Could you please have a try on the repro steps I have provided?
Thanks in advance...
Please see comment in #4669.
I also check the package of Microsoft.PowerShell.SDK. I think the package has the similar issue which I have mentioned in the origin post. Please take a look at section:
My analyze & questions for your reference
@xycui The problem is that you are building against full .net, you'd have to use .net core or .net standard instead
What are you trying to achieve on a high level? the SMA package is just for referencing the API's, it does not do anything by itself. Do you want to host PowerShell instead (then you should use the SDK package) and are you clear on the difference between PowerShell v5 (also known as Windows PowerShell) vs v6 (PowerShell Core, which this repo is about)? From a .Net app, I would only expect that referencing the Windows PowerShell assemblies to work.
For hosting PowerShell, if you're specifically targeting the .Net Framework runtime, you should be using https://www.nuget.org/packages/Microsoft.PowerShell.5.ReferenceAssemblies/ which targets Windows PowerShell (built on .Net Framework). Otherwise, Microsoft.PowerShell.SDK is specifically for PSCore6 which is targeting the .Net Core runtime.
@SteveL-MSFT Thanks for the reply. This is what I need.
@bergmeister Thanks for your note.
I know the SMA is just for reference. But the net standard version of SMA package cannot work on .NET Framework target. Which really confused me. I know there is another System.Management.Automation.dll package. But that is 3 years ago version. I thought that might be replaced by the NET standard one. And now I know that this package is just for .NET Core environment.
@SteveL-MSFT Maybe the package (PowerShell.SDK and System.Management.Automation) could be package to netcore? Just because net standard could also be used by net framework target? Or any doc for the case of net framework to use Microsoft.PowerShell.5.ReferenceAssemblies instead.
https://github.com/PowerShell/PowerShell/issues/8721 is opened for changing the target framework for SDK nuget package to netcoreapp2.1
Most helpful comment
For hosting PowerShell, if you're specifically targeting the .Net Framework runtime, you should be using https://www.nuget.org/packages/Microsoft.PowerShell.5.ReferenceAssemblies/ which targets Windows PowerShell (built on .Net Framework). Otherwise, Microsoft.PowerShell.SDK is specifically for PSCore6 which is targeting the .Net Core runtime.