diff --git a/.pipelines/verifyCommonProps.ps1 b/.pipelines/verifyCommonProps.ps1 index 6a0c4e9b261e..37e51e915ae8 100644 --- a/.pipelines/verifyCommonProps.ps1 +++ b/.pipelines/verifyCommonProps.ps1 @@ -1,61 +1,65 @@ +<# +.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 ) -# scan all csharp project in the source directory -function Get-CSharpProjects { - param ( - [string]$path - ) +$hasInvalidCsProj = $false - # Get all .csproj files under the specified path - return Get-ChildItem -Path $path -Recurse -Filter *.csproj | Select-Object -ExpandProperty FullName -} +$csprojFiles = [System.IO.Directory]::EnumerateFiles($sourceDir, '*.csproj', [System.IO.SearchOption]::AllDirectories) -# Check if the project file imports 'Common.Dotnet.CsWinRT.props' -function Test-ImportSharedCsWinRTProps { - param ( - [string]$filePath - ) +foreach ($csprojFile in $csprojFiles) { + $filename = [System.IO.Path]::GetFileName($csprojFile) - # Load the XML content of the .csproj file - [xml]$csprojContent = Get-Content -Path $filePath + # Skip the CmdPal extension template project, which doesn't require the shared props. + if ($filename -eq 'TemplateCmdPalExtension.csproj') { + continue + } - - # 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') } -} + $importExists = $false -# Call the function with the provided source directory -$csprojFilesArray = Get-CSharpProjects -path $sourceDir + try { + $xml = New-Object System.Xml.XmlDocument -$hasInvalidCsProj = $false + $xml.Load($csprojFile) -# Enumerate the array of file paths and call Validate-ImportSharedCsWinRTProps for each file -foreach ($csprojFile in $csprojFilesArray) { - # Skip if the file ends with 'TemplateCmdPalExtension.csproj' - if ($csprojFile -like '*TemplateCmdPalExtension.csproj') { - continue - } - - # The CmdPal.Core projects use a common shared props file, so skip them - if ($csprojFile -like '*Microsoft.CmdPal.Core.*.csproj') { - continue - } - if ($csprojFile -like '*Microsoft.CmdPal.Ext.Shell.csproj') { - continue - } + # 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) - # The PowerAccent.Common project does not target WinRT, so skip it - if ($csprojFile -like '*PowerAccent.Common.csproj') { + 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 } - $importExists = Test-ImportSharedCsWinRTProps -filePath $csprojFile - if (!$importExists) { - Write-Output "$csprojFile need to import 'Common.Dotnet.CsWinRT.props'." + if (-not $importExists) { + Write-Output "$csprojFile needs to import 'Common.Dotnet.CsWinRT.props' or 'Common.Dotnet.props'." $hasInvalidCsProj = $true } } @@ -64,4 +68,4 @@ if ($hasInvalidCsProj) { exit 1 } -exit 0 \ No newline at end of file +exit 0 diff --git a/PowerToys.slnx b/PowerToys.slnx index 932b6ccf7e11..3b9e54c2ca1f 100644 --- a/PowerToys.slnx +++ b/PowerToys.slnx @@ -9,11 +9,11 @@ - + - + @@ -56,8 +56,8 @@ - + @@ -203,11 +203,11 @@ - + - + @@ -718,11 +718,11 @@ - + - + @@ -1101,6 +1101,7 @@ + @@ -1122,14 +1123,14 @@ + + - - diff --git a/src/Common.Dotnet.CsWinRT.props b/src/Common.Dotnet.CsWinRT.props index 5cfb3d5aba73..8dffc0d80a94 100644 --- a/src/Common.Dotnet.CsWinRT.props +++ b/src/Common.Dotnet.CsWinRT.props @@ -1,47 +1,22 @@ - - - - net10.0 - 10.0.26100.68-preview - $(CoreTargetFramework)-windows10.0.26100.0 - 10.0.19041.0 - 10.0.19041.0 - win-x64;win-arm64 - - - - - 4 - - True - CA1824;CA1416;CA1720;CA1859;CA2263;CA2022;MVVMTK0045;MVVMTK0049 - + + + - - true - DEBUG;TRACE - portable - false - - - - prompt - RELEASE;TRACE - pdbonly - true - + + - +    + diff --git a/src/Common.Dotnet.props b/src/Common.Dotnet.props new file mode 100644 index 000000000000..a6714d91f1fd --- /dev/null +++ b/src/Common.Dotnet.props @@ -0,0 +1,38 @@ + + + + + + net10.0 + 10.0.26100.68-preview + $(CoreTargetFramework)-windows10.0.26100.0 + 10.0.19041.0 + 10.0.19041.0 + win-x64;win-arm64 + + + + + 4 + + True + CA1824;CA1416;CA1720;CA1859;CA2263;CA2022;MVVMTK0045;MVVMTK0049 + + + + + true + DEBUG;TRACE + portable + false + + + + + prompt + RELEASE;TRACE + pdbonly + true + + + diff --git a/src/modules/poweraccent/PowerAccent.Common/PowerAccent.Common.csproj b/src/modules/poweraccent/PowerAccent.Common/PowerAccent.Common.csproj index 4ac857a002bb..c637bb02700a 100644 --- a/src/modules/poweraccent/PowerAccent.Common/PowerAccent.Common.csproj +++ b/src/modules/poweraccent/PowerAccent.Common/PowerAccent.Common.csproj @@ -1,13 +1,12 @@ - + + + - - net10.0-windows10.0.26100.0 enable disable + true