mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-08-29 10:09:43 +02:00
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Separates out the common .NET build properties from **Common.Dotnet.CsWinRT.props** into a new file so POCO libraries don't have to import WinRT or add exclusions to **verifyCommonProps.ps1**. Also updates the verify script for robustness and speed. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments This is a follow-on from #47211, which included a C# project that didn't target WinRT. Previously, all C# projects were mandated to include **Common.Dotnet.CsWinRT.props**, even if they didn't need the WinRT import, because the common .NET build properties like `TargetFramework` and Debug/Release configuration were included in the same file. This PR separates out the non-WinRT information into a new **Common.Dotnet.props** file. The existing **Common.Dotnet.CsWinRT.props** file imports this, meaning no changes are required for existing C# projects. Additionally, the **verifyCommonProps.ps1** script has been updated to remove redundant exclusions, add checks for malformed XML, and to speed up the scan. ### Changes to verifyCommonProps.ps1 The following updates were made: - Added descriptive header and param info. - Now using .NET's `EnumerateFiles()` instead of Powershell's slow file enumeration. - Now using `XmlDocument.Load()` to quickly load the content of the file. - Parsing the document now uses `GetElementsByTagName()` with a '*' wildcard for the namespace to pull out `Import` tags regardless of location or ns prefix. - Removed prior exclusions for **Microsoft.CmdPal.Core.*** and **Microsoft.CmdPal.Ext.Shell** projects. There are no Core projects any longer and the **Microsoft.CmdPal.Ext.Shell** project already includes an import for **Common.Dotnet.CsWinRT.props**. - Filename comparisons now use an exact match to the filename itself rather than a wildcard substring match. This means the check is robust against project names with the same suffix. - Early exit `break` on successful match, so the whole file need not be scanned. - `try/catch` added to prevent a .csproj XML parsing error from breaking the CI. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed - Built all Quick Accent projects and confirmed all unit tests passed. - Edited a .csproj to exclude the end tag. Ran **verifyCommonProps.ps1** to confirm the parsing error was reported. - Edited **verifyCommonProps.ps1** to remove the exclusion for **TemplateCmdPalExtension.csproj**. Ran the script to confirm that the file was correctly flagged. - Edited **PowerAccent.Common.csproj** to remove the Import for **Common.Dotnet.props**. Ran the verify script to confirm that the file was correctly flagged. - Edited **PowerAccent.Core.csproj** to remove the Import for **Common.Dotnet.CsWinRT.props**. Ran the verify script to confirm that the file was correctly flagged. ## Verify Script Performance File cache|Before (ms)|After (ms) --|--|-- Cold|3123|1739 Warm|1849|686
72 lines
2.1 KiB
PowerShell
72 lines
2.1 KiB
PowerShell
<#
|
|
.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
|