Create a NuGet package that shows update notifications

后端 未结 3 1109
滥情空心
滥情空心 2021-01-18 14:05

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 rep

相关标签:
3条回答
  • 2021-01-18 14:42

    In the end, I've found no better way to show a notification than through the init.ps1 file.
    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.

    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)
    }
    
    0 讨论(0)
  • 2021-01-18 14:42

    I have an open source .net monitoring solution called "Wolfpack" and one of the plugins allows you to monitor for updates to one or more NuGet packages. You can also track across multiple feeds too.

    Might be a bit overkill but it will do the job. You can also get notified via email, growl or roll your own notification mechanism.

    The instructions for this plugin are here: http://wolfpackcontrib.codeplex.com/wikipage?title=WolfPack.Contrib.Checks.NuGet&referringTitle=Home

    0 讨论(0)
  • 2021-01-18 14:49
    1. Really nothing wrong with it...
    2. You can use Write-Host to push it to the package manager console.
    0 讨论(0)
提交回复
热议问题