Create a NuGet package that shows update notifications

I am creating a NuGet package and I would like the package to display a notification when an update for the package is present in the repository (this is a private repository, not the official NuGet repository).

Please note: I do not want the package to be automatically updated (in case the new version may cause some problems), but just inform the user about it.

To do this, I added this to my init.ps1file 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
}

Verification is $update.Version -gt $package.Versionnecessary so as not to show a notification when installing a newer package.

I would like to know if

  • This solution is acceptable, or if there is a better and β€œstandard” way to do it (instead of brewing your own solution).
  • , MessageBox : " ", , , "".
+5
3

, , init.ps1.
, init script , , , .

, , , , - .

param($installPath, $toolsPath, $package, $project)
if ($project -eq $null) {
    $projet = Get-Project
}

$PackageName = "MyPackage"
$update = Get-Package -Updates -Source 'MySource' | Where-Object { $_.Id -eq $PackageName }
# the check on $u.Version -gt $package.Version is needed to avoid showing the notification
# when the newer package is being installed
if ($update -ne $null -and $update.Version -gt $package.Version) {

    $msg = "An update is available for package $($PackageName): version $($update.Version)"

    # method 1: a MessageBox
    [System.Windows.Forms.MessageBox]::Show($msg) | Out-Null
    # method 2: Write-Host
    Write-Host $msg
    # method 3: navigate to a web page with EnvDTE
    $project.DTE.ItemOperations.Navigate("some-url.html", [EnvDTE.vsNavigateOptions]::vsNavigateOptionsNewWindow) | Out-Null
    # method 4: show a message in the Debug/Build window
    $win = $project.DTE.Windows.Item([EnvDTE.Constants]::vsWindowKindOutput)
    $win.Object.OutputWindowPanes.Item("Build").OutputString("Update available"); 
    $win.Object.OutputWindowPanes.Item("Build").OutputString([Environment]::NewLine)
}
+3
  • ...
  • Write-Host, .
0

All Articles