我需要編寫NuGet包install.ps1腳本,將原生dll文件複製到輸出目錄,但我找不到獲取輸出文件夾路徑的方式。如何通過PowerShell獲取NuGet輸出目錄?
我認爲解決方案是使用類似如下:
$solutionDir = [System.IO.Path]::GetDirectoryName($dte.Solution.FullName) + "\"
我怎樣才能獲得通過PowerShell中的輸出目錄路徑?
我需要編寫NuGet包install.ps1腳本,將原生dll文件複製到輸出目錄,但我找不到獲取輸出文件夾路徑的方式。如何通過PowerShell獲取NuGet輸出目錄?
我認爲解決方案是使用類似如下:
$solutionDir = [System.IO.Path]::GetDirectoryName($dte.Solution.FullName) + "\"
我怎樣才能獲得通過PowerShell中的輸出目錄路徑?
我開始「走了」,直到我發現:
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
}
通過「輸出目錄」你的意思是輸出目錄的項目?如果是這樣,您可以通過項目迭代找到一個由指數再抓項目的基本目錄,像這樣(假設你確定你感興趣的項目是在指數3:
$project = $dte.Solution.Projects.Item(3)
($project.Properties | Where Name -match FullPath).Value
然後獲得構建路徑(BIN \ Debug或Bin \釋放)你這樣做:
($project.ConfigurationManager.ActiveConfiguration.Properties | Where Name -match OutputPath).Value
您也可以訪問活動項目的解決方案,像這樣:
$project = $dte.ActiveSolutionProjects