-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateContractAssemblies.ps1
70 lines (59 loc) · 3.06 KB
/
generateContractAssemblies.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Generate Contract Assemblies, for each Target Framework, which will be used as reference assemblies during ApiCompat validation
# Directory structure under contractAssemblies will be as following:
# $contractAssembliesPath\{TargetFramework}\{ReferenceAssembly.dll}
$implementationAssembliesRootPath = "$PSScriptRoot\src"
$contractAssembliesPath = "$PSScriptRoot\Tools\apiCompat\contractAssemblies"
Write-Host "============================ `n"
Write-Host "implementationAssembliesRootPath: $implementationAssembliesRootPath"
Write-Host "contractAssembliesPath: $contractAssembliesPath `n"
# remove existing contract assemblies
if (Test-Path $contractAssembliesPath)
{
Write-Host ">>> Remove-Item -Recurse -Force $contractAssembliesPath"
Remove-Item -Recurse -Force $contractAssembliesPath
}
# create contractAssembliesDir
Write-Host ">>> mkdir $contractAssembliesPath"
mkdir $contractAssembliesPath | Out-Null
# recursively iterate implAssembliesRootPath and include DLLs whose name contain 'IdentityModel'
Get-ChildItem $implementationAssembliesRootPath -Recurse -Include '*IdentityModel*.dll' | Foreach-Object `
{
# get partialAssemblyName - remove text before the first dot e.g. System.IdentityModel.Tokens.Jwt -> IdentityModel.Tokens.Jwt
# this hack is in place as there are cases when a project is producing an assembly with a name different than its name (special builds)
$null = $_.Name -match "^*\.(?<partialName>.*).dll$"
$partialAssemblyName = $matches["partialName"]
# continue if source path [string] of current item (assembly) doesn't contain partialAssemblyName
# we don't want assemblies that don't belong to IdentityModel-extensions solution in contractAssemblies e.g. 'Microsoft.IdentityModel.Clients.ActiveDirectory.dll'
if (!($_.Directory -match $partialAssemblyName))
{
# think continue;
return
}
# resolve target framework, destination directory and destination assembly file path
$targetFramework = Split-Path $_.Directory -leaf
$destDir = Join-Path -Path $contractAssembliesPath -ChildPath $targetFramework
$destAssemblyFilePath = Join-Path -Path $destDir -ChildPath $_.Name
# create directory if it doesn't exist already
if (!(Test-Path $destDir))
{
Write-Host ">>> New-Item -ItemType directory $destDir | Out-Null"
New-Item -ItemType directory $destDir | Out-Null
}
# if an assembly with the same name as the current item (assembly) already exists in destination dir
# overwrite it only if curent item's LastWriteTime is greater than LastWriteTime of an existing assembly
if (Test-Path $destAssemblyFilePath)
{
$destAssemblyFile = Get-Item $destAssemblyFilePath
if ($_.LastWriteTime -gt $destAssemblyFile.LastWriteTime)
{
Write-Host ">>> Copy-Item $_ -Destination $destDir"
Copy-Item $_ -Destination $destDir
}
}
else # copy assembly to destination dir
{
Write-Host ">>> Copy-Item $_ -Destination $destDir"
Copy-Item $_ -Destination $destDir
}
}
Write-Host "`nDone!`n"