Skip to content

Commit 2878dc3

Browse files
committed
Add Powershell script to validate whether CSharp project correctly import shared props, update pipeline to enforce such validation, and fixed all projects that didn't import this shared props correctly
1 parent cca3f44 commit 2878dc3

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

.pipelines/v2/templates/job-build-project.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ jobs:
314314
flattenFolders: True
315315
OverWrite: True
316316

317+
# Check if all projects import common props.
318+
- pwsh: |-
319+
& '.pipelines/verifyCommonProps.ps1' -sourceDir '$(build.sourcesdirectory)'
320+
displayName: Audit projects for shared common props
321+
317322
# Check if deps.json files don't reference different dll versions.
318323
- pwsh: |-
319324
& '.pipelines/verifyDepsJsonLibraryVersions.ps1' -targetDir '$(build.sourcesdirectory)\$(BuildPlatform)\$(BuildConfiguration)'

.pipelines/verifyCommonProps.ps1

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[CmdletBinding()]
2+
Param(
3+
[Parameter(Mandatory = $True, Position = 1)]
4+
[string]$sourceDir
5+
)
6+
7+
# scan all csharp project in the source directory
8+
function Get-CSharpProjects {
9+
param (
10+
[string]$path
11+
)
12+
13+
# Get all .csproj files under the specified path
14+
$csprojFiles = Get-ChildItem -Path $path -Recurse -Filter *.csproj
15+
16+
# Initialize an array to hold the file paths
17+
$csprojArray = @()
18+
19+
foreach ($file in $csprojFiles) {
20+
# Add the full path of each .csproj file to the array
21+
$csprojArray += $file.FullName
22+
}
23+
24+
# Return the array
25+
return $csprojArray
26+
}
27+
28+
# Check if the project file imports 'Common.Dotnet.CsWinRT.props'
29+
function Test-ImportSharedCsWinRTProps {
30+
param (
31+
[string]$filePath
32+
)
33+
34+
# Load the XML content of the .csproj file
35+
[xml]$csprojContent = Get-Content -Path $filePath
36+
37+
38+
# Check if the Import element with Project attribute containing 'Common.Dotnet.CsWinRT.props' exists
39+
return $csprojContent.Project.Import | Where-Object { $null -ne $_.Project -and $_.Project.EndsWith('Common.Dotnet.CsWinRT.props') }
40+
}
41+
42+
# Call the function with the provided source directory
43+
$csprojFilesArray = Get-CSharpProjects -path $sourceDir
44+
45+
$hasInvalidCsProj = $false
46+
47+
# Enumerate the array of file paths and call Validate-ImportSharedCsWinRTProps for each file
48+
foreach ($csprojFile in $csprojFilesArray) {
49+
$importExists = Test-ImportSharedCsWinRTProps -filePath $csprojFile
50+
if (!$importExists) {
51+
Write-Output "$csprojFile need to import 'Common.Dotnet.CsWinRT.props'."
52+
$hasInvalidCsProj = $true
53+
}
54+
}
55+
56+
if ($hasInvalidCsProj) {
57+
exit 1
58+
}
59+
60+
exit 0

src/modules/AdvancedPaste/AdvancedPaste.FuzzTests/AdvancedPaste.FuzzTests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<!-- Look at Directory.Build.props in root for common stuff as well -->
3+
<Import Project="..\..\Common.Dotnet.CsWinRT.props" />
4+
25
<PropertyGroup>
3-
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
46
<LangVersion>latest</LangVersion>
57
<ImplicitUsings>enable</ImplicitUsings>
68
<Nullable>enable</Nullable>

src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<!-- Look at Directory.Build.props in root for common stuff as well -->
3+
<Import Project="..\..\Common.Dotnet.CsWinRT.props" />
4+
25
<PropertyGroup>
3-
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
46
<LangVersion>latest</LangVersion>
57
<ImplicitUsings>enable</ImplicitUsings>
68
</PropertyGroup>

0 commit comments

Comments
 (0)