Powershell 获取与 ProjectItem 关联的所有文件名

Powershell get all filenames associated to a ProjectItem

我想用 powershell 获取 ProjectItem 下的所有文件

在上面我想要以下文件的路径:

我可以毫无问题地获取 ProjectItem,但我不知道如何枚举 FileNames 数组。所有的元素似乎都指向同一件事,所以我想我一定是在枚举数组时出错了。

$projectItem.FileNames(0) => Path to web.config
$projectItem.FileNames(1) => Path to web.config

这里的任何数字似乎return相同的文件路径。

如何从 powershell 中的 ProjectItem 获取所有 3 个文件路径

要尝试将其放入 Web 项目的包管理器控制台中:

@(Get-Project).ProjectItems | Where {$_.Name.StartsWith("Web") } | Select { $_.FileNames(0) }

知道了。基本上,您必须扩展名为 Web.configProjectItemProjectItems 集合。不过,可能还有更简单的方法。

$webconfig = @(Get-Project).ProjectItems |
    Where-Object { $_.Name -eq "Web.config" }

$webconfig.Properties("LocalPath").Value # path for web.config

$webdebugconfig = $webconfig.ProjectItems |
    Where-Object { $_.Name -eq "Web.Debug.config" }

$webdebugconfig.Properties("LocalPath").Value # path for web.debug.config

$webreleaseconfig = $webconfig.ProjectItems |
    Where-Object { $_.Name -eq "Web.Release.config" }

$webreleaseconfig.Properties("LocalPath").Value # path for web.release.config