Skip to content

Conversation

@JohnMcPMS
Copy link
Member

@JohnMcPMS JohnMcPMS commented Nov 14, 2025

Change

Adds scripts to view the nuget package references in C++ projects and update them en-masse. Use them to update C++/WinRT and WIL to the latest version.

Get-VcxprojNugetPackageVersions

This script lets you get the set of packages in use by all C++ projects. You can provide a -PackageFilter to target a specific package. It gives you a link to the package on nuget.org to use in the update script.

> .\src\Get-VcxprojNugetPackageVersions.ps1
Starting search from: D:\winget-cli\src
Output format: Table
Found 48 .vcxproj files

=== PACKAGE DETAILS ===

Name                                                  Count
----                                                  -----
Microsoft.Windows.CppWinRT, 2.0.250303.1                 13
Microsoft.Windows.ImplementationLibrary, 1.0.250325.1    15


=== PACKAGE URLS ===
  Microsoft.Windows.CppWinRT : https://www.nuget.org/packages/Microsoft.Windows.CppWinRT#versions-body-tab
  Microsoft.Windows.ImplementationLibrary : https://www.nuget.org/packages/Microsoft.Windows.ImplementationLibrary#versions-body-tab

=== PROJECT DETAILS ===

ProjectName                                  PackageId                               Version      TargetFramework
-----------                                  ---------                               -------      ---------------
AppInstallerCLI                              Microsoft.Windows.CppWinRT              2.0.250303.1 native
[... removed full list for brevity ...]
UndockedRegFreeWinRT                         Microsoft.Windows.ImplementationLibrary 1.0.250325.1 native


=== SUMMARY ===
Total .vcxproj files found: 48
Projects with packages.config: 16
Projects without packages.config: 32
Total package references: 28

Script completed.

Update-VcxprojNugetPackageVersions

This script updates a single package to a new version across all projects. It supports -WhatIf to inspect what will happen before doing it (although I would always suggest running it on a clean git state so that you can undo easily).

> .\Update-VcxprojNugetPackageVersions.ps1 -PackageName Microsoft.Windows.ImplementationLibrary -NewVersion 1.0.250325.1
Starting package version update process...
Package: Microsoft.Windows.ImplementationLibrary
New Version: 1.0.250325.1
Backup files: Disabled

Searching for projects using package 'Microsoft.Windows.ImplementationLibrary'...
Found 15 reference(s) to package 'Microsoft.Windows.ImplementationLibrary'

Projects to update:
  AppInstallerCLICore - Version(s): 1.0.231028.1
[... removed full list for brevity ...]
  UndockedRegFreeWinRT - Version(s): 1.0.231028.1

Starting updates...
Updated packages.config: D:\winget-cli\src\AppInstallerCLICore\packages.config
  Microsoft.Windows.ImplementationLibrary: 1.0.231028.11.0.250325.1
Updated .vcxproj file: D:\winget-cli\src\AppInstallerCLICore\AppInstallerCLICore.vcxproj
  Replaced 4 reference(s): Microsoft\.Windows\.ImplementationLibrary\.1\.0\.231028\.1 → Microsoft.Windows.ImplementationLibrary.1.0.250325.1
[... removed full list for brevity ...]

=== UPDATE SUMMARY ===
Package: Microsoft.Windows.ImplementationLibrary
New Version: 1.0.250325.1
Projects found with package: 15
packages.config files updated: 15
.vcxproj files updated: 15

Versions being replaced:
  1.0.231028.1 (in 15 project(s))

Update process completed!
Microsoft Reviewers: Open in CodeFlow

@github-actions

This comment was marked as outdated.

<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
</Target>
</Project>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: two empty lines


[CmdletBinding()]
param(
[ValidateSet("Table", "CSV", "JSON", "Object")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all of these? I don't see why we would ever use anything but Object

[ValidateSet("Table", "CSV", "JSON", "Object")]
[string]$OutputFormat = "Table",

[string]$ExportPath,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? If I want to write to file I can just | Out-File (and apply whatever format I want inbetween)

try {
$vcxprojFiles = Get-ChildItem -Path $SearchPath -Filter "*.vcxproj" -Recurse -ErrorAction SilentlyContinue
if (-not $SuppressOutput) {
Write-Host "Found $($vcxprojFiles.Count) .vcxproj files" -ForegroundColor Green
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write-Verbose ?

$packages = @()

if (-not (Test-Path $PackagesConfigPath)) {
Write-Verbose "No packages.config found for project: $ProjectName"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AI does know about Write-Verbose!


# Main execution
try {
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$PSScriptRoot

Shows what changes would be made without actually making them.
.PARAMETER Backup
Creates backup files (.bak) before making changes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I like git...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wanted to default that on...

Comment on lines +134 to +135
$oldPattern = [regex]::Escape("$PackageName.$OldVersion")
$newPattern = "$PackageName.$NewVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not much of a concern, but this wouldn't work if a package adds a props or targets file in the new version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm expecting that if that happens we will have to apply it to a single project and then figure out how to get that into the rest of them. On the plus side, the Get script makes for an easier starting point.

Copy link
Member

@florelis florelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like some things about it, but if it works well enough and we're not shipping it...

@JohnMcPMS JohnMcPMS merged commit 0d5b16b into microsoft:master Nov 15, 2025
9 checks passed
@JohnMcPMS JohnMcPMS deleted the update-cppwinrt branch November 15, 2025 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants