尝试从PowerShell运行ASP.NET Core 1.1 xunit测试覆盖率但没有成功。运行时我收到以下错误:
System.IO.FileNotFoundException:无法加载文件或程序集System.Runtime,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其中一个依赖项。该系统找不到指定的文件
在PowerShell行(最后一行):
$solutionDir = "C:\Projects\AdministrationPortal.RestAPI"
$openCoverDir = (Get-ChildItem $packagesDir -filter "OpenCover*" -Directory | % { $_.fullname })
$openCoverRunner = "$openCoverDir\tools\OpenCover.Console.exe"
$packagesDir = $solutionDir + "\packages"
$xunitRunnerDir = (Get-ChildItem $packagesDir -filter "xunit.runner.console*" -Directory | % { $_.fullname })
$xunitRunner = "$xunitRunnerDir\tools\xunit.console.exe"
$unitTestsProjDir = (Get-ChildItem $solutionDir\test -filter "*Test*" - Directory | % { $_.fullname })
$testsDllDir = "$unitTestsProjDir\bin\Debug\netcoreapp1.1"
$testDllFile = (Get-ChildItem $testsDllDir -File | Where-Object {$_.Name -like "*Test*.dll" -and $_.Name -notlike "*xunit.runner.visualstudio.testadapter*" } )
$testDll = "$testsDllDir\$testDllFile"
$categories = "Integration;Unit"
$nameSpaceToTest = "AdminPortal.RestAPI.Areas.FeatureToggle.Services;AdminPortal.RestAPI.Areas.FeatureToggle.Storage;AdminPortal.RestAPI.Areas.Text.Services;AdminPortal.RestAPI.Areas.Text.Storage"
$nameSpaceToSkip = ""
$assemblyToTest = "AdminPortal.RestAPI"
$categoriesArray = (($categories -split ';') | ? {$_})
$nameSpaceToTestArray = (($nameSpaceToTest -split ';') | ? {$_})
$nameSpaceToSkipArray = (($nameSpaceToSkip -split ';') | ? {$_})
ForEach ($item In $nameSpaceToTestArray) {
$nameSpaceArray += "+[$assemblyToTest*]" + $item + "* " }
ForEach ($item In $nameSpaceToSkipArray) {
$nameSpaceArray += "-[$assemblyToTest*]" + $item + "* " }
$coverageReportDir = "C:\tmp\Coverage"
foreach ($item in $categoriesArray) {
$coverageReportXML = $coverageReportDir + "\coverage." + $item + ".xml"
Write-Output $coverageReportXML
& $openCoverRunner -register:user -target:"$xunitRunner" "-targetargs:$testDll" -targetdir:"$testsDllDir" -output:"$coverageReportXML" "-filter:$nameSpaceArray"
}
最初的想法是,.NET Framework 4.6没有System.Runtime,但后来我添加了具有它的其他框架导入,但结果是相同的。测试项目的project.json文件:
{
"version": "1.0.0-*",
"testRunner": "xunit",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
},
"xunit": "2.2.0-beta5-build3474",
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"xunit.runner.visualstudio": "2.2.0-beta3-build1187",
"Moq": "4.6.38-alpha",
"System.Linq": "4.3.0",
"Microsoft.DotNet.InternalAbstractions": "1.0.0",
"OpenCover": "4.6.519",
"ReportGenerator": "2.5.2",
"Microsoft.CodeCoverage": "1.0.2",
"xunit.runner.console": "2.2.0-beta5-build3474",
"System.Runtime": "4.3.0",
"AdminPortal.RestAPI": "1.0.0-*"
},
"frameworks": {
"netcoreapp1.1": {
"imports": [
"dnxcore50",
"dotnet5.6",
"portable-net46"
]
}
}
}