我需要编写NuGet包install.ps1脚本,它将原生dll文件复制到输出目录,但我找不到获取输出文件夹路径的方法。
我认为解决方案是使用以下内容:
$solutionDir = [System.IO.Path]::GetDirectoryName($dte.Solution.FullName) + "\"
如何通过PowerShell获取输出目录路径?
答案 0 :(得分: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
答案 1 :(得分: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
}