I am creating a NuGet package, and I would like the package to display a notification whenever an update for the package is present in the repository (which is a private repository, not the official NuGet repository).
Please note that I do not want the package to update itself automatically (in case the new version might introduce some problems), but just notify the user.
To do this, I added this in my init.ps1 file in the package:
param($installPath, $toolsPath, $package, $project)
$PackageName = "MyPackage"
$update = Get-Package -Updates | Where-Object { $_.Id -eq $PackageName }
if ($update -ne $null -and $update.Version -gt $package.Version) {
[System.Windows.Forms.MessageBox]::Show("New version $($update.Version) available for $($PackageName)") | Out-Null
}
The check on $update.Version -gt $package.Version is needed to avoid showing the notification when the newer package is being installed.
I would like to know if
- This solution is acceptable, or if there is a better and “standard” way to do this (rather than brewing my own solution).
- There is a better way to show a notification, as the
MessageBoxis rather annoying: it hides behind the “preparing solution” dialog when I open the project, and the operation does not complete until I click ok.
In the end, I’ve found no better way to show a notification than through the
init.ps1file.I also discovered that the init script is run only if the Package Manager Console is visible, which is not exactly ideal for this purpose, but still I couldn’t find anything better.
About the way to notify the user, I’ve found some methods, which I’m posting here in case they might be useful for someone else.