NuGet init.ps1导致调试进入控制台

时间:2021-01-22 00:34:07

We have an in-house NuGet package that has a readme.txt file that we want to display when the package is installed. To accomplish this we created a very simple init.ps1 file for the package that looks like:

我们有一个内部NuGet包,它有一个readme.txt文件,我们想在安装包时显示它。为此,我们为包创建了一个非常简单的init.ps1文件,如下所示:

param($installPath, $toolsPath, $package, $project)

$path = [System.IO.Path]
$readmefile = $path::Combine($installPath, "content\Content\fonts\globalcons\readme.txt")
$DTE.ItemOperations.OpenFile($readmefile)

It does what it's supposed to and opens the readme.txt when the package is installed, but it also spews the following in the Package Manager Console.

它可以执行它应该的操作并在安装软件包时打开readme.txt,但它也会在软件包管理器控制台中显示以下内容。

AutoHides             : False
Caption               : readme.txt
Collection            : {Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase, Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase, Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase, 
                        Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase...}
CommandBars           : 
ContextAttributes     : System.__ComObject
DTE                   : EnvDTE.DTEClass
Document              : System.__ComObject
HWnd                  : 0
Height                : 1039
IsFloating            : False
Kind                  : Document
Left                  : 1951
Linkable              : False
LinkedWindowFrame     : Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase
LinkedWindows         : 
Object                : System.__ComObject
ObjectKind            : {8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}
Project               : System.__ComObject
ProjectItem           : System.__ComObject
Selection             : System.__ComObject
Top                   : 106
Type                  : vsWindowTypeDocument
Visible               : True
Width                 : 1432
WindowState           : vsWindowStateMaximize
HasBeenDeleted        : False
Events                : Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowEvents
VisibilityEvents      : Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowVisibilityEvents
Rect                  : 1951,106,1432,1039
OutstandingEventCount : 0

I know it's the aforementioned script that's causing it because if I comment out the $DTE.ItemOperations.OpenFile($readmefile) line the output doesn't show up in the Package Manager Console. What I can't figure out is what I'm doing wrong that is causing the output to show up every time.

我知道这是上面提到的脚本,因为如果我注释掉$ DTE.ItemOperations.OpenFile($ readmefile)行,输出就不会出现在Package Manager Console中。我无法弄清楚的是,我做错了导致输出每次出现。

1 个解决方案

#1


1  

You don't need an init.ps1 file to get a readme.txt displayed. NuGet natively supports this as long as there is a readme.txt in the root folder of the package. Note NuGet only displays the readme.txt for the package being installed and not for any packages it depends on.

您不需要init.ps1文件来显示readme.txt。只要包的根文件夹中有readme.txt,NuGet本身就支持这一点。注意NuGet仅显示正在安装的软件包的readme.txt,而不显示它所依赖的任何软件包。

But if you want to stick with your current approach, cast the return value from this method to [void]:

但是,如果您想坚持使用当前的方法,请将此方法的返回值转换为[void]:

[void]$DTE.ItemOperations.OpenFile($readmefile)

#1


1  

You don't need an init.ps1 file to get a readme.txt displayed. NuGet natively supports this as long as there is a readme.txt in the root folder of the package. Note NuGet only displays the readme.txt for the package being installed and not for any packages it depends on.

您不需要init.ps1文件来显示readme.txt。只要包的根文件夹中有readme.txt,NuGet本身就支持这一点。注意NuGet仅显示正在安装的软件包的readme.txt,而不显示它所依赖的任何软件包。

But if you want to stick with your current approach, cast the return value from this method to [void]:

但是,如果您想坚持使用当前的方法,请将此方法的返回值转换为[void]:

[void]$DTE.ItemOperations.OpenFile($readmefile)