-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Expand file tree
/
Copy pathverifyCommonProps.ps1
More file actions
71 lines (55 loc) · 2.11 KB
/
Copy pathverifyCommonProps.ps1
File metadata and controls
71 lines (55 loc) · 2.11 KB
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
<#
.SYNOPSIS
Validates that all C# projects in the repository import a required shared props file.
.DESCRIPTION
Recursively searches for .csproj files under the given root directory and checks that
each one imports either Common.Dotnet.CsWinRT.props or Common.Dotnet.props. These
shared MSBuild props files enforce consistent build settings across all C# projects.
.PARAMETER sourceDir
Root directory to recursively search for .csproj files.
.OUTPUTS
Writes the path of any non-conforming or malformed .csproj file to the output stream.
Exits with code 1 if any such files are found, and with code 0 otherwise.
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $True, Position = 1)]
[string]$sourceDir
)
$hasInvalidCsProj = $false
$csprojFiles = [System.IO.Directory]::EnumerateFiles($sourceDir, '*.csproj', [System.IO.SearchOption]::AllDirectories)
foreach ($csprojFile in $csprojFiles) {
$filename = [System.IO.Path]::GetFileName($csprojFile)
# Skip the CmdPal extension template project, which doesn't require the shared props.
if ($filename -eq 'TemplateCmdPalExtension.csproj') {
continue
}
$importExists = $false
try {
$xml = New-Object System.Xml.XmlDocument
$xml.Load($csprojFile)
# The '*' wildcard matches Import elements regardless of XML namespace.
foreach ($importNode in $xml.GetElementsByTagName('Import', '*')) {
if ($null -ne $importNode.Project) {
$importFilename = [System.IO.Path]::GetFileName($importNode.Project)
if ($importFilename -eq 'Common.Dotnet.CsWinRT.props' -or $importFilename -eq 'Common.Dotnet.props') {
$importExists = $true
break
}
}
}
}
catch {
Write-Output "Error parsing ${csprojFile}: $_"
$hasInvalidCsProj = $true
continue
}
if (-not $importExists) {
Write-Output "$csprojFile needs to import 'Common.Dotnet.CsWinRT.props' or 'Common.Dotnet.props'."
$hasInvalidCsProj = $true
}
}
if ($hasInvalidCsProj) {
exit 1
}
exit 0