'Powershell 5.1 fails to work with .net library that has reference to .net standard 2.0 package

I have a simple .net 4.6.2 library project named MSProject that consumes Buildalyzer 2.6.0 package (which is .net standard 2.0 compatible).

To test if my MSProject works I added a simple console app built on .net 4.6.2. After run I get an expected result -> so we are cool here.

The problem appears when I try to consume my MSProject from PowerShell (version 5.1). I use the following simple code:

Add-Type -Path 'D:\MSProject\MSProject\bin\Debug\MSProject.dll'
$analyzer = [MSProject.MSProjectAnalyzer]::new()
$files = $analyzer.GetProjectItems('D:\MSProject\ConsoleApp\ConsoleApp.csproj')

it fails with the following error:

Exception calling "GetProjectItems" with "1" argument(s): "Could not load file or assembly
'System.Reflection.TypeExtensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified."
At line:1 char:1
+ $projectFilesList = $msProjectAnalyzer.GetProjectItems('E:\CHC\McKess ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

It's not really clear why powershell even tries to look for System.Reflection.TypeExtensions, Version=4.1.0.0 whereas the MSProject has a dependency on System.Reflection.TypeExtensions, Version=4.1.4.0

P.S. I added projects to the GitHub.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source