我在使用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)也会出现同样的问题
从微软文档中应该实现AddFolder:https://docs.microsoft.com/en-ca/dotnet/api/envdte.projectitems?view=visualstudiosdk-2017#Methods
我已经安装了Visual Studio 2017 SDK并且没有问题调用:
EnvDTE.ProjectItems.AddFromFile(字符串)
文档是错的还是我错过了什么?
找到答案,使用Get-Interface
cmdlet时会产生问题。它由于某些原因删除了它所使用的类的实现。
删除Get-Interface
和([EnvDTE.ProjectItems])
修复了问题:
$folderItems = $deployFolder.ProjectItems