【问题标题】:Relative Path not working in powershell when passing parameters to Pickles Cmdlet / Nuget将参数传递给 Pickles Cmdlet / Nuget 时,相对路径在 powershell 中不起作用
【发布时间】:2014-01-24 12:33:34
【问题描述】:

我正在使用 pickles NuGet 包来生成 DHTML 功能文件网页,以便可以将它们发布到 Intranet 站点上。我在 VS2012 的包管理器控制台中使用相对路径来执行此操作:-

PM> Pickle-Features -FeatureDirectory .\FIX_SpecflowTests\Specs -OutputDirectory .\FIX_SpecflowTests\Pickles -SystemUnderTestName FIX_SpecflowTests -DocumentationFormat DHTML -TestResultsFile .\FIX_SpecflowTests\bin\Debug\TestResult.xml

产生了这个输出:-

Pickles v.0.13.1.0

Generating documentation based on the following parameters
----------------------------------------------------------
Feature Directory         : C:\svn\local\BakeryDemoTest\trunk\AllBakeryDemoTestProjects\FIX_SpecflowTests\Specs
Output Directory          : C:\svn\local\BakeryDemoTest\trunk\AllBakeryDemoTestProjects\FIX_SpecflowTests\Pickles
Project Name              : FIX_SpecflowTests
Project Version           : 
Language                  : 
Incorporate Test Results? : Yes
Test Result Format        : NUnit
Test Result File          : C:\svn\local\BakeryDemoTest\trunk\AllBakeryDemoTestProjects\FIX_SpecflowTests\bin\Debug\TestResult.xml
Pickles completed successfully
PM> 

可爱!但是,由于安装了 Visual Studio 更新 4 和 Nuget 更新,相对路径已经停止工作,所以我得到了这个输出:-

Pickles v.0.13.1.0

Generating documentation based on the following parameters
----------------------------------------------------------
Feature Directory         : C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\FIX_SpecflowTests\Specs
Output Directory          : C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\FIX_SpecflowTests\Pickles
Project Name              : FIX_SpecflowTests
Project Version           : 
Language                  : 
Incorporate Test Results? : Yes
Test Result Format        : NUnit
Test Result File          : C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\FIX_SpecflowTests\bin\Debug\TestResult.xml
Pickle-Features : Could not find a part of the path 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\FIX_SpecflowTests\Specs'.
At line:1 char:16
+ Pickle-Features <<<<  -FeatureDirectory .\FIX_SpecflowTests\Specs -OutputDirectory .\FIX_SpecflowTests\Pickles -SystemUnderTestName FIX_SpecflowTests -DocumentationFormat DHTML -TestResultsFile .\FIX_SpecflowTests\bin\Debug\TestResult.xml
+ CategoryInfo          : NotSpecified: (:) [Pickle-Features], DirectoryNotFoundException
+ FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,PicklesDoc.Pickles.PowerShell.Pickle_Features

PM> 

如您所见,正在使用的基本路径位于 VS2012 安装目录中,而不是解决方案目录。有谁知道如何正确设置包管理器的“基本”路径以从中计算出相对路径?

最终我想从 VS2012 外部将它作为 Powershell 脚本运行,但我认为我需要先从包管理器中让它工作!

【问题讨论】:

    标签: powershell visual-studio-2012 nuget relative-path solution


    【解决方案1】:

    我并没有完全找到答案,但我确实找到了解决方法 - 只是实现了 powershell 脚本。我使用了来自Run NUnit tests from powershell 的 sn-p 作为指导 - 我将在这里总结一下我实际做了什么:-

    1. 获取当前目录并存储(假设我在项目目录中)
    2. 然后上一层并存储它(假设我现在在解决方案目录中)
    3. 设置我的输出文件夹(我只在发布版本中这样做,而不是调试)
    4. 通过 nunit 运行测试
    5. 运行泡菜
    6. 运行规范流报告
    $scriptpath = $MyInvocation.MyCommand.Path $dir = 拆分路径 $scriptpath 光盘$目录 光盘../ $SolutionDir = 获取位置 $OutDir = "$dir\bin\Release" $nunit = "$SolutionDir\packages\NUnit.Runners.2.6.3\tools\nunit-console.exe" $tests = (Get-ChildItem $OutDir -Recurse -Include *Tests.dll) & $nunit /noshadow /framework:"net-4.5" /xml:"$OutDir\TestResult.xml" $tests "/out:$OutDir\TestResult.txt" 写主机“我的包在 $SolutionDir/packages\Pickles.0.13.1.0\tools\PicklesDoc.Pickles.PowerShell.dll” 导入模块 $SolutionDir/packages\Pickles.0.13.1.0\tools\PicklesDoc.Pickles.PowerShell.dll Pickle-Features -FeatureDirectory $dir\Specs -OutputDirectory $dir\Pickles -SystemUnderTestName FIX_SpecflowTests -DocumentationFormat DHTML -TestResultsFile $dir\bin\Release\TestResult.xml 光盘$目录 $specflowReporter = "$SolutionDir\packages\SpecFlow.1.9.0\tools\specflow.exe" $proj = "FIX_SpecflowTests.csproj" $xml = "$OutDir\TestResult.xml" & $specflowReporter nunitexecutionreport $proj /xmlTestResult:"$xml" /out:"$OutDir\TestResult.html"

    【讨论】:

    • 如果有人知道如何回答原始问题,即如何设置包管理器的工作位置,它是相对路径的基本路径,我仍然会很感激答案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    相关资源
    最近更新 更多