Can PowerShell use a local assembly with a different version in the GAC?

I need to specify System.Net.Http.dllversion 2.2.29.0 in a PowerShell script. GAC has System.Net.Httpversion 4.0.0.0. Is it possible to redirect to a local DLL without changing the GAC?

I tried:

  • Adding a DLL through Add-Type -Path 'System.Net.Http.dll'.
  • Creating a .config file with an element <assemblyBinding>, such as what .NET applications use to link redirects.
  • Download DLL via [Reflection.Assembly]::LoadFrom("$PSScriptRoot\System.Net.Http.dll").

In all cases, subsequent execution [AppDomain]::CurrentDomain.GetAssemblies()shows that version 4.0.0.0 is C:\Windowsstill the only downloaded copy.

+4
source share
1

? ?

Add-Type -AssemblyName "Microsoft.SqlServer.SMO, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"

:

[reflection.assembly]::Load("Microsoft.SqlServer.SMO, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91")

,

0

Source: https://habr.com/ru/post/1651685/


All Articles