NuGet init.ps1 导致在控制台中调试
NuGet init.ps1 causing debug into in console
我们有一个内部 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)
它按照预期的方式运行并在安装包时打开 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
我知道是上述脚本导致的,因为如果我注释掉 $DTE.ItemOperations.OpenFile($readmefile)
行,输出不会显示在程序包管理器控制台中。我想不通的是我做错了什么导致输出每次都出现。
您不需要 init.ps1 文件来显示 readme.txt。只要包的根文件夹中有一个 readme.txt,NuGet 本身就支持它。注意 NuGet 只显示正在安装的包的 readme.txt 而不是它所依赖的任何包。
但是如果您想坚持使用当前的方法,请将此方法中的 return 值转换为 [void]
:
[void]$DTE.ItemOperations.OpenFile($readmefile)
我们有一个内部 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)
它按照预期的方式运行并在安装包时打开 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
我知道是上述脚本导致的,因为如果我注释掉 $DTE.ItemOperations.OpenFile($readmefile)
行,输出不会显示在程序包管理器控制台中。我想不通的是我做错了什么导致输出每次都出现。
您不需要 init.ps1 文件来显示 readme.txt。只要包的根文件夹中有一个 readme.txt,NuGet 本身就支持它。注意 NuGet 只显示正在安装的包的 readme.txt 而不是它所依赖的任何包。
但是如果您想坚持使用当前的方法,请将此方法中的 return 值转换为 [void]
:
[void]$DTE.ItemOperations.OpenFile($readmefile)