3

我需要编写将本机 dll 文件复制到输出目录的 NuGet 包 install.ps1 脚本,但我找不到获取输出文件夹路径的方法。

我认为解决方案是使用以下内容:

$solutionDir = [System.IO.Path]::GetDirectoryName($dte.Solution.FullName) + "\"

如何通过 PowerShell 获取输出目录路径?

4

2 回答 2

3

“输出目录”是指项目的输出目录吗?如果是这样,您可以遍历项目以按索引查找一个,然后像这样获取项目的基本目录(假设您已经确定您感兴趣的项目位于索引 3:

 $project = $dte.Solution.Projects.Item(3)
 ($project.Properties | Where Name -match FullPath).Value

然后要获取构建路径(bin\debug 或 bin\release),请执行以下操作:

($project.ConfigurationManager.ActiveConfiguration.Properties | Where Name -match OutputPath).Value

您还可以像这样访问解决方案中的活动项目:

 $project = $dte.ActiveSolutionProjects
于 2013-10-16T16:20:47.153 回答
1

我开始“向上走”,直到找到它:

param($installPath, $toolsPath, $package, $project)
if ($project -eq $null) {
$project = Get-Project
}


Write-Host "installPath:" "${installPath}"
Write-Host "toolsPath:" "${toolsPath}"
Write-Host "package:" "${package}"
<# Write-Host "project:" "${project}" #>
Write-Host " "

<# Recursively look for a .sln file starting with the installPath #>
$parentFolder = (get-item $installPath)
do {
        $parentFolderFullName = $parentFolder.FullName

        $latest = Get-ChildItem -Path $parentFolderFullName -File -Filter *.sln | Select-Object -First 1
        if ($latest -ne $null) {
            $latestName = $latest.name
            Write-Host "${latestName}"
        }

        if ($latest -eq $null) {
            $parentFolder = $parentFolder.parent    
        }
}
while ($parentFolder -ne $null -and $latest -eq $null)
<# End recursive search for .sln file #>


if ( $parentFolder -ne $null -and $latest -ne $null )
{
    <# Create a base directory to store Solution-Level items #>
    $myFolderFullName = $parentFolder.FullName
}
于 2013-10-16T15:42:49.117 回答