Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to output debugging messages from install.ps1 in NuGet

I am developing a NuGet package, including an install.ps1 script which runs during the package installation. I would like to be able to output messages from my script and also output the results of running .bat files from within my sript.

Here is my install.ps1:

param($installPath, $toolsPath, $package, $project)
Write-Output "Running install.ps1 for MyPkg"
Set-Location $toolsPath
.\helper.bat | Write-Output

When I install my package in Visual Studio, then I look in the Package Manager option in the Output page, I see:

Executing script file 'C:\Test\packages\MyPkg.1\tools\install.ps1'.

and it seems the script is working (I can tell in other ways that helper.bat ran), but I don't see any of the output. How can I get the output working?

like image 200
JoelFan Avatar asked Apr 27 '12 15:04

JoelFan


People also ask

How do I debug a NuGet package?

In order to use Source Code to debug the code form a NuGet package, we need to enable it in Visual Studio. Under the Debug menu, click on Options. First, under General, tick the option to Enable Source Link support. Next, we need to add the NuGet symbol server to the locations where Visual Studio look symbol files.

Which command is used for downloading and installing a package from NuGet repository?

The NuGet CLI restore command downloads and installs any missing packages. The command works on projects that use either PackageReference or packages.


1 Answers

I could not get the output when installing from the NuGet Package Manager Dialog, I'll dig a bit later to see where it's going.

But you should be able to see it when installing from the Nuget console (Tools->Library Package Manager->Package Manager Console). The output went directly in the console. Example :

PM> uninstall-package samplepackage
hello from unninstal.ps1
Successfully removed 'samplepackage 1.0.0' from WebApplication24.

unninstal.ps1 :

param($installPath, $toolsPath, $package, $project)
Write-Host "hello from unninstal.ps1"
like image 137
Alexandre Dion Avatar answered Nov 09 '22 05:11

Alexandre Dion