Skip to content

Commit

Permalink
Resolves Newtonsoft.Json loading against 2019 version of the TFS Clie…
Browse files Browse the repository at this point in the history
…ntOM (#594)

Fixes #580
  • Loading branch information
jessehouwing authored and Danny McCormick committed Dec 12, 2019
1 parent 6ebfd5e commit 4399893
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions powershell/VstsTaskSdk/ServerOMFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,31 @@ function Get-TfsClientCredentials {
# Get the endpoint.
$endpoint = Get-Endpoint -Name SystemVssConnection -Require

# Test if the Newtonsoft.Json DLL exists in the OM directory.
$newtonsoftDll = [System.IO.Path]::Combine($OMDirectory, "Newtonsoft.Json.dll")
Write-Verbose "Testing file path: '$newtonsoftDll'"
if (!(Test-Path -LiteralPath $newtonsoftDll -PathType Leaf)) {
Write-Verbose 'Not found. Rethrowing exception.'
throw
}

# Add a binding redirect and try again. Parts of the Dev15 preview SDK have a
# dependency on the 6.0.0.0 Newtonsoft.Json DLL, while other parts reference
# the 8.0.0.0 Newtonsoft.Json DLL.
Write-Verbose "Adding assembly resolver."
$onAssemblyResolve = [System.ResolveEventHandler] {
param($sender, $e)

if ($e.Name -like 'Newtonsoft.Json, *') {
Write-Verbose "Resolving '$($e.Name)' to '$newtonsoftDll'."

return [System.Reflection.Assembly]::LoadFrom($newtonsoftDll)
}

return $null
}
[System.AppDomain]::CurrentDomain.add_AssemblyResolve($onAssemblyResolve)

# Validate the type can be found.
$null = Get-OMType -TypeName 'Microsoft.TeamFoundation.Client.TfsClientCredentials' -OMKind 'ExtendedClient' -OMDirectory $OMDirectory -Require

Expand Down

0 comments on commit 4399893

Please sign in to comment.