dotcover.exe中出现NUnit访问被拒绝错误



我正在为dotCover编写PowerShell脚本,以使用NUnit-console.exe生成覆盖率报告在我运行脚本之后-

$testRunner="C:Program Files (x86)NUnit 2.6.2binnunit-console.exe"
$testContainers="path/to/test1.dll","path/to/test2.dll"
$dotcover="D:JetBrains.dotCover.CommandLineTools.2019.3.4dotcover.exe"
foreach($test in $testContainers)
{
$testAssembly=Get-Item $test
$testName= $testAssembly.BaseName
&$dotcover cover /TargetExecutable=$testRunner /TargetArguments=$test /Output="D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReport$testName.dcvr"
}
$testReports=$testContainer|%{
$testAssembly=Get-Item $test
$name= $testAssembly.BaseName
return ("D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReport{0}.dcvr" -f $name)
}
$testReportArguments=[String]::Join(";",$testReports)
&$dotcover merge /Source="$testReportArguments" /Output="D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReportmergedReport.dcvr" /ReportType="DCVR"

&$dotcover report /Source="D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReportmergedReport.dcvr" /Output="D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReportmergedReport.html" /ReportType="HTML"

它给出了以下错误-

Unhandled Exception:
System.UnauthorizedAccessException: Access to the path 'C:Program Files (x86)NUnit 2.6.2binTestResult.xml' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String 
msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path)
at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
at NUnit.ConsoleRunner.Runner.Main(String[] args)

即使TestResult.xml文件不在那个位置,它也在-

C:Program Files (x86)NUnit 2.6.2docfilesTestResult.xml

但我复制了那个文件并将其放入bin文件夹,但错误仍然存在。这个问题与权利有关吗?有什么办法摆脱这个吗?并且在此之后,执行处于停止状态,既不失败也不通过。

任何时候你看到"访问被拒绝",那么是的,这是权限/ACL问题。所以,你确实需要检查一下。

老实说,我建议将这些"exe"路径添加到Windows系统路径或PowerShell环境路径中。然而,根据我在评论中包含的链接:

PowerShell:运行可执行文件

  1. 呼叫接线员&

原因:

用于将字符串视为SINGLE命令。有助于处理空间。在PowerShell V2.0中,如果您正在运行7z.exe(7-Zip.exe(或另一个以数字开头的命令,您必须使用命令调用运算符&。PowerShell V3.0解析器立即执行更聪明的是,在这种情况下,你不需要&不再

详细信息:

运行命令、脚本或脚本块。呼叫接线员,也称为作为"调用运算符",可以运行存储在变量,并用字符串表示。因为呼叫接线员不解析命令,它无法解释命令参数

# Example:
& 'C:Program FilesWindows Media Playerwmplayer.exe' "c:videosmy home video.avi"  /fullscreen

当外部命令有很多参数时,事情可能会变得棘手或者参数或路径中有空格!

有了空格,你必须嵌套引号,结果不是始终保持畅通!

在这种情况下,最好像这样分离所有内容:

$CMD  =  'SuperApp.exe'
$arg1 =  'filename1'
$arg2 =  '-someswitch'
$arg3 =  'C:documents and settingsuserdesktopsome other file.txt'
$arg4 =  '-yetanotherswitch'
& $CMD $arg1 $arg2 $arg3 $arg4
# or same like that:
$AllArgs =  @('filename1',  '-someswitch', 'C:documents and settingsuserdesktopsome other file.txt', '-yetanotherswitch')
& 'SuperApp.exe' $AllArgs

所以,这个改变应该会让你继续前进。同样,我不使用该工具,因此无法验证,因此您可能需要进行调整。

另请参阅:

从Powershell 实现DotCover

$testRunner     = 'C:Program Files (x86)NUnit 2.6.2binnunit-console.exe'
$testContainers = 'path/to/test1.dll','path/to/test2.dll'
$dotcover       = 'D:JetBrains.dotCover.CommandLineTools.2019.3.4dotcover.exe'
foreach($test in $testContainers)
{
$testAssembly = Get-Item $test
$testName     = $testAssembly.BaseName
$arg1 = 'cover'
$arg2 = '/TargetExecutable = $testRunner'
$arg3 = '/TargetArguments = $test'
$arg4 = '/TargetExecutable = $testRunner'
$arg5 = '/Output = "D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReport$testName.dcvr"'
& $dotcover $arg1 $arg2 $arg3 $arg4 $arg5
}
$testReports  = $testContainer | 
%{
$testAssembly = Get-Item $test
$name = $testAssembly.BaseName
return ('D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReport{0}.dcvr' -f $name)
}
$testReportArguments = [String]::Join(';',$testReports)
$arg1 = 'merge'
$arg2 = '/Source = $testReportArguments'
$arg3 = '/Output = "D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReportmergedReport.dcvr"'
$arg4 = '/ReportType = "DCVR"'
& $dotcover $arg1 $arg2 $arg3 $arg4

$arg1 = 'report'
$arg2 = '/Source = "D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReportmergedReport.dcvr"'
$arg3 = '/Output = "D:JetBrains.dotCover.CommandLineTools.2019.3.4TestReportmergedReport.html"'
$arg4 = '/ReportType="HTML"'
& $dotcover $arg1 $arg2 $arg3 $arg4

最新更新