如何从蛋糕(构建)发起HTML报告
问题描述:
我在我的项目中使用蛋糕来建立,运行单元测试,检查代码覆盖率,然后生成一个HTML报告(使用ReportGenerator)。这一切工作正常,我可以在浏览器中打开生成的报告。如何从蛋糕(构建)发起HTML报告
但是,当我以前使用dos批处理文件来执行此操作时,它也会启动我的默认浏览器并在生成后加载报告,但我找不到用蛋糕做到这一点的方法。
这里是我一直在使用批处理文件的内容:使用以下
@ECHO OFF
SET SearchDirectory=%~dp0Grapevine.Tests\bin\Debug
SET DllContainingTests=%~dp0Grapevine.Tests\bin\Debug\Grapevine.Tests.dll
for /R "%~dp0packages" %%a in (*) do if /I "%%~nxa"=="xunit.console.exe" SET TestRunnerExe=%%~dpnxa
for /R "%~dp0packages" %%a in (*) do if /I "%%~nxa"=="OpenCover.Console.exe" SET OpenCoverExe=%%~dpnxa
for /R "%~dp0packages" %%a in (*) do if /I "%%~nxa"=="ReportGenerator.exe" SET ReportGeneratorExe=%%~dpnxa
if not exist "%~dp0GeneratedReports" mkdir "%~dp0GeneratedReports"
call :RunOpenCoverUnitTestMetrics
if %errorlevel% equ 0 (
call :RunReportGeneratorOutput
)
if %errorlevel% equ 0 (
call :RunLaunchReport
)
exit /b %errorlevel%
:RunOpenCoverUnitTestMetrics
"%OpenCoverExe%"^
-target:"%TestRunnerExe%"^
-targetargs:"\"%DllContainingTests%\""^
-filter:"+[*]* -[*.Tests*]* -[*]*.*Config -[xunit*]* -[*]Grapevine.Interfaces.*"^
-mergebyhash^
-skipautoprops^
-register:user^
-output:"%~dp0GeneratedReports\CoverageReport.xml"^
-searchdirs:"%SearchDirectory%"
exit /b %errorlevel%
:RunReportGeneratorOutput
"%ReportGeneratorExe%"^
-reports:"%~dp0\GeneratedReports\CoverageReport.xml"^
-targetdir:"%~dp0\GeneratedReports\ReportGeneratorOutput"
exit /b %errorlevel%
:RunLaunchReport
start "report" "%~dp0\GeneratedReports\ReportGeneratorOutput\index.htm"
exit /b %errorlevel%
我曾尝试:
StartProcess(new FilePath("./GeneratedReports/ReportGeneratorOutput/index.htm"));
对此我收到以下错误:
An error occured when executing task 'generate-report'.
Error: The specified executable is not a valid application for this OS platform.
我有ve确认路径正确且文件存在,并且在命令行上复制/粘贴文件路径确实会在我的默认浏览器中打开该文件。
答
您可以使用StartProcess
别名例子做到这一点:
FilePath reportpath = File("./GeneratedReports/ReportGeneratorOutput/index.htm");
StartProcess(reportpath);
答
什么终于为我工作是这样的:
if (IsRunningOnWindows())
{
StartProcess("explorer.exe", reportPath);
}
显然,这不会在非Windows环境下工作,但这超出了我的需求范围。我试过的其他东西都会产生一个错误,无论是找不到该文件还是该可执行文件对操作系统无效。
这没有奏效。看到我上面的编辑。 –