Visual Studio 2017 SDK does not implement all methods in PowerShell

时间:2018-02-26 17:56:31

标签: visual-studio powershell visual-studio-sdk

I am executing a PowerShell script when initializing a NuGet dependency with the Visual Studio NuGet Package Manager and I have an error stating that EnvDTE.ProjectItems.AddFolder(string, string) is not implemented :

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

Here is the script in question :

$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

The same problem happens with EnvDTE.ProjectItems.AddFromDirectory(String)

from the microsoft documentation AddFolder should be implemented: https://docs.microsoft.com/en-ca/dotnet/api/envdte.projectitems?view=visualstudiosdk-2017#Methods

I have installed the Visual Studio 2017 SDK and have no problem calling:

EnvDTE.ProjectItems.AddFromFile(String)

Are the docs wrong or am I missing something?

1 个答案:

答案 0 :(得分:0)

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

删除Get-Interface([EnvDTE.ProjectItems]) 解决了这个问题:

$folderItems = $deployFolder.ProjectItems