forked from chriseyre2000/Powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckProject.ps1
100 lines (70 loc) · 3.82 KB
/
CheckProject.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<#
.Synopsis
Extracts the name and version number from a Nuget package name in the form PACKAGE.NAME.1.2.4
#>
function Parts()
{
[CmdletBinding()]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromPipeline=$true,
Position=0)]
[string]
$full
)
$name = ($full -split "\." | % { if( $_ -notMatch "[0-9]+") {$_} } ) -join "."
$version = ($full -split "\." | % { if( $_ -Match "[0-9]+") {$_} } ) -join "."
$result = new-object PSObject
$result | Add-Member -MemberType NoteProperty -Name id -Value $name
$result | Add-Member -MemberType NoteProperty -Name version -Value $version
return $result
}
#dir -Recurse D:\dev\AzureTraining\Loggingv2\*.config
# From project file find the assemblies with explicit hint paths:
[xml]$data = get-content D:\dev\AzureTraining\Loggingv2\LoggingWorkerRole\LoggingWorkerRole.csproj
#These are the assemblies that have hint paths with exlicit numbers
$data.Project.ItemGroup.Reference.HintPath | % { $_ -split "\\" | select -Skip 2 -First 1 | Parts} | where id -NE "" | sort id
#This gets the version number
#("Microsoft.Data.Edm.5.2.0" -split "\." | % { if( $_ -Match "[0-9]+") {$_} } ) -join "."
#..\packages\Microsoft.Data.Edm.5.2.0\lib\net40\Microsoft.Data.Edm.dll
#..\packages\Microsoft.Data.OData.5.2.0\lib\net40\Microsoft.Data.OData.dll
#..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.0.0\lib\net40\Microsoft.WindowsAzure.Configuration.dll
#..\packages\WindowsAzure.Storage.2.0.5.1\lib\net40\Microsoft.WindowsAzure.Storage.dll
#..\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll
#These are what nuget will fetch
[xml]$data = get-content D:\dev\AzureTraining\Loggingv2\LoggingWorkerRole\packages.config
$data.packages.package
#id version targetFramework
#-- ------- ---------------
#Microsoft.Data.Edm 5.2.0 net45
#Microsoft.Data.OData 5.2.0 net45
#Microsoft.WindowsAzure.ConfigurationManager 2.0.0.0 net45
#System.Spatial 5.2.0 net45
#WindowsAzure.Storage 2.0.5.1 net45
#These are the redirects
[xml]$data = get-content D:\dev\AzureTraining\Loggingv2\LogViewerWebRole\web.config
$data.configuration.runtime.assemblyBinding.dependentAssembly | select @{Name="id"; Expression={$_.assemblyIdentity.Name}},
@{Name="oldVersion"; Expression={$_.bindingRedirect.oldVersion}},
@{Name="version"; Expression={$_.bindingRedirect.newVersion}}
# Now we have the pieces it should be simple to build a comparison tool
<#
.Synopsis
Identifies that a mapping is applied
.Example
IsInRange -range "1.0.0.0-4.0.0.0" -testValue "4.0.1.0"
#>
function IsInRange([string]$range, [string]$testValue) {
$valueVersion = [Version]::Parse($testValue)
$lowVersion = [Version]::Parse( ( $range -split "-" | select -first 1 ) )
$highVersion = [Version]::Parse( ( $range -split "-" | select -first 1 -Skip 1 ) )
if( $value -le $lowRange) {
return $false
}
if ( $value -gt $highRange) {
return $false
}
return $true
}