Skip to content

Commit ba11c82

Browse files
committed
Update README.md
Changed documentation to show local check and made some adjustments to make it easier to understand and use for new users.
1 parent e976a54 commit ba11c82

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,21 @@ sourceManager.AddSource("msstore", "https://storeedgefd.dsx.mp.microsoft.com/v9.
101101

102102
### Find Latest Versions of a Package:
103103

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.
104+
Using the ***WinGetPackageManager*** class you can use the `GetInstalledPackages` capability to get the latest version of a package and then retrieve the version number from the `AvailableVersion` property.
105105

106-
You would then 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.
106+
You would then be able to compare this to the current version of the package and determine if you need to notify users of an available upgrade.
107107

108108
```csharp
109+
Version currentPackageVersion = null;
109110
Version latestPackageVersion = null;
110111
WinGetPackageManager packageManager = new WinGetPackageManager();
111112
string packageId = "nkdAgility.AzureDevOpsMigrationTools";
112-
var package = packageManager.SearchPackage(PackageId).SingleOrDefault();
113+
var package = packageManager.GetInstalledPackages(packageId, true).FirstOrDefault();
114+
currentPackageVersion = new Version(package.Version);
113115
latestPackageVersion = new Version(package.AvailableVersion);
114116

115-
var version = Assembly.GetEntryAssembly().GetName().Version;
116-
if (latestPackageVersion > version)
117+
if (latestPackageVersion > currentPackageVersion)
117118
{
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);
119+
Console.WriteLine("You are currently running version {currentVersion} and a newer version ({latestVersion}) is available. You should update now using Winget command 'winget {packageId}' from the Windows Terminal.", currentPackageVersion, latestPackageVersion, packageId);
120120
}
121121
```

0 commit comments

Comments
 (0)