Skip to content

Commit 733ccb4

Browse files
committed
Added find package version to readme.
1 parent 8d2daae commit 733ccb4

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,24 @@ The code for adding a source could look like this:
9898
WinGetSourceManager sourceManager = new WinGetSourceManager();
9999
sourceManager.AddSource("msstore", "https://storeedgefd.dsx.mp.microsoft.com/v9.0", "Microsoft.Rest");
100100
```
101+
102+
### Find Latest Versions of a Package:
103+
104+
Using the ***WinGetPackageManager*** class you can use the `SearchPackage` capability to get the latest version of a package and then retrieve the version number from the `AvailableVersion` property.
105+
106+
You would thn be able to compare this to the latest version of your executing assembly and determine if you need to notify users of an available upgrade.
107+
108+
```csharp
109+
Version latestPackageVersion = null;
110+
WinGetPackageManager packageManager = new WinGetPackageManager();
111+
string packageId = "nkdAgility.AzureDevOpsMigrationTools";
112+
var package = packageManager.SearchPackage(PackageId).SingleOrDefault();
113+
latestPackageVersion = new Version(package.AvailableVersion);
114+
115+
var version = Assembly.GetEntryAssembly().GetName().Version;
116+
if (latestPackageVersion > version)
117+
{
118+
// Notify user of available upgrade
119+
_logger.LogWarning("You are currently running version {version} and a newer version ({latestVersion}) is available. You should update now using Winget command 'winget {packageId}' from the Windows Terminal.", version, latestPackageVersion, packageId);
120+
}
121+
```

0 commit comments

Comments
 (0)