【问题标题】:How can I get the NuGet output directory through PowerShell?如何通过 PowerShell 获取 NuGet 输出目录?
【发布时间】:2013-10-16 14:58:10
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: powershell nuget


    【解决方案1】:

    “输出目录”是指项目的输出目录吗?如果是这样,您可以遍历项目以按索引找到一个,然后像这样获取项目的基本目录(假设您已确定您感兴趣的项目位于索引 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
    

    【讨论】:

      【解决方案2】:

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

      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
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多