Visual Studio 2017 SDK 未实现 PowerShell 中的所有方法

Visual Studio 2017 SDK does not implement all methods in PowerShell

在使用 Visual Studio NuGet 包管理器初始化 NuGet 依赖项时,我正在执行 PowerShell 脚本,但出现错误,指出 EnvDTE.ProjectItems.AddFolder(string, string) 未实现:

Exception calling "AddFolder" with "1" argument(s): "Exception calling "InvokeMethod" with "3" argument(s): "Not implemented (Exception from HRESULT: 0x80004001 (E_NOTIMPL))""

这是有问题的脚本:

$deployFolder = $solution.Projects | where-object { $_.ProjectName -eq "Packages" } | select -first 1

$folderItems = Get-Interface $deployFolder.ProjectItems ([EnvDTE.ProjectItems])

# add all our support deploy scripts to our Support solution folder
ls $deployTarget | foreach-object {
    if (Test-Path $_.FullName -PathType Container) {
        $folderItems.AddFolder($_.FullName)
    }
} > $null

同样的问题发生在 EnvDTE.ProjectItems.AddFromDirectory(String)

应实施 Microsoft 文档中的 AddFolder: https://docs.microsoft.com/en-ca/dotnet/api/envdte.projectitems?view=visualstudiosdk-2017#Methods

我安装了Visual Studio 2017 SDK,调用没有问题:

EnvDTE.ProjectItems.AddFromFile(String)

文档有误还是我遗漏了什么?

找到答案,问题是在使用 Get-Interface cmdlet 时产生的。由于某些原因,它删除了它所使用的 class 的实现。

删除 Get-Interface([EnvDTE.ProjectItems]) 修复了问题:

$folderItems = $deployFolder.ProjectItems