diff --git a/.pipelines/v2/templates/job-build-project.yml b/.pipelines/v2/templates/job-build-project.yml index f55d9f71a9fc..be822e5cc956 100644 --- a/.pipelines/v2/templates/job-build-project.yml +++ b/.pipelines/v2/templates/job-build-project.yml @@ -314,6 +314,11 @@ jobs: flattenFolders: True OverWrite: True + # Check if all projects (located in src sub-folder) import common props + - pwsh: |- + & '.pipelines/verifyCommonProps.ps1' -sourceDir '$(build.sourcesdirectory)\src' + displayName: Audit shared common props for CSharp projects in src sub-folder + # Check if deps.json files don't reference different dll versions. - pwsh: |- & '.pipelines/verifyDepsJsonLibraryVersions.ps1' -targetDir '$(build.sourcesdirectory)\$(BuildPlatform)\$(BuildConfiguration)' diff --git a/.pipelines/verifyCommonProps.ps1 b/.pipelines/verifyCommonProps.ps1 new file mode 100644 index 000000000000..da2caf700ff9 --- /dev/null +++ b/.pipelines/verifyCommonProps.ps1 @@ -0,0 +1,60 @@ +[CmdletBinding()] +Param( + [Parameter(Mandatory = $True, Position = 1)] + [string]$sourceDir +) + +# scan all csharp project in the source directory +function Get-CSharpProjects { + param ( + [string]$path + ) + + # Get all .csproj files under the specified path + $csprojFiles = Get-ChildItem -Path $path -Recurse -Filter *.csproj + + # Initialize an array to hold the file paths + $csprojArray = @() + + foreach ($file in $csprojFiles) { + # Add the full path of each .csproj file to the array + $csprojArray += $file.FullName + } + + # Return the array + return $csprojArray +} + +# Check if the project file imports 'Common.Dotnet.CsWinRT.props' +function Test-ImportSharedCsWinRTProps { + param ( + [string]$filePath + ) + + # Load the XML content of the .csproj file + [xml]$csprojContent = Get-Content -Path $filePath + + + # Check if the Import element with Project attribute containing 'Common.Dotnet.CsWinRT.props' exists + return $csprojContent.Project.Import | Where-Object { $null -ne $_.Project -and $_.Project.EndsWith('Common.Dotnet.CsWinRT.props') } +} + +# Call the function with the provided source directory +$csprojFilesArray = Get-CSharpProjects -path $sourceDir + +$hasInvalidCsProj = $false + +# Enumerate the array of file paths and call Validate-ImportSharedCsWinRTProps for each file +foreach ($csprojFile in $csprojFilesArray) { + $importExists = Test-ImportSharedCsWinRTProps -filePath $csprojFile + if (!$importExists) { + Write-Output "$csprojFile need to import 'Common.Dotnet.CsWinRT.props'." + $hasInvalidCsProj = $true + } +} + +if ($hasInvalidCsProj) { + exit 1 +} + +exit 0 \ No newline at end of file diff --git a/src/Common.Dotnet.FuzzTest.props b/src/Common.Dotnet.FuzzTest.props new file mode 100644 index 000000000000..d0749d516abf --- /dev/null +++ b/src/Common.Dotnet.FuzzTest.props @@ -0,0 +1,10 @@ + + + + + + net8.0-windows10.0.19041.0 + + diff --git a/src/modules/AdvancedPaste/AdvancedPaste.FuzzTests/AdvancedPaste.FuzzTests.csproj b/src/modules/AdvancedPaste/AdvancedPaste.FuzzTests/AdvancedPaste.FuzzTests.csproj index f22ee39381d4..2d0b5f1ad18a 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste.FuzzTests/AdvancedPaste.FuzzTests.csproj +++ b/src/modules/AdvancedPaste/AdvancedPaste.FuzzTests/AdvancedPaste.FuzzTests.csproj @@ -1,6 +1,8 @@ + + + - net8.0-windows10.0.19041.0 latest enable enable diff --git a/src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj b/src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj index 714b9ec3acd8..8c0f107395c2 100644 --- a/src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj +++ b/src/modules/Hosts/Hosts.FuzzTests/Hosts.FuzzTests.csproj @@ -1,6 +1,9 @@  + + + + - net8.0-windows10.0.19041.0 latest enable