Visual Studio 2017 SDK does not implement all methods in PowerShell

0

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?

visual-studio
powershell
visual-studio-sdk
asked on Stack Overflow Feb 26, 2018 by Samuel Rondeau-Millaire • edited Feb 27, 2018 by Joy

1 Answer

0

Found the answer, the problem is created when using the Get-Interface cmdlet. It removes for some reasons the implementation of the class it is used on.

Removing the Get-Interface and the ([EnvDTE.ProjectItems]) fixed the problem:

$folderItems = $deployFolder.ProjectItems

User contributions licensed under CC BY-SA 3.0