Search code examples
raketeamcityteamcity-7.0dotcoveralbacore

Why does this dotCover rake task fail using these relative file paths?


I'm having some issues getting dotCover to work in an Albacore exec task using relative paths.

@xUnitRunnerPath = Pathname.new('../../Tools/xUnit/xunitcontrib-dotcover.2.0/xunit.runner.utility.dll').realpath
@myTestDll = 'C:\PathToProj\My.Project.Tests\bin\Release\My.project.Tests.dll'
@outputDir = 'C:\PathToTestResults\'

exec :testCoverage do |cmd|
    cmd.command = "C:/BuildAgent/tools/dotCover/dotCover.exe"
    cmd.parameters = [
        "cover",
        "/targetexecutable=$$#{@xUnitRunnerPath}$$",
        "/targetarguments=$$#{@myTestDll}$$",
        "/output=#{@outputDir}/My.Project.Tests.dll.dcvr"
    ]
end

The dotCover error is unhelpful just telling me paths are wrong

Failed to convert relative paths to absolute in parameters for the 'cover' 
command. The given path's format is not supported. 

This doesn't provide much help and I've also tried dotcover help cover for the help on that but doesn't give many clues as to what's going wrong.

I've followed this post about rake and dotcover and also this question. Maybe I'm missing the relevant documentation here but it would be really helpful to be able to get this working.


EDIT: I just found this relating to relative and absolute paths, perhaps because I'm using absolute paths I need the following. We'll find out tomorrow

/AnalyseTargetArguments=false

Solution

  • For anyone that's interested here's my final rake tasks working

    task :unitTestsWithCoverageReport => [ :unitTestsWithCoverage, :coverageServiceMessage ]
    
    exec :unitTestsWithCoverage do |cmd|
        fullPathAssemblies = []
    
        @unitTestAssemblies.each do |testAssembly|
            testAssemblyRealPath = Pathname.new(testAssembly).realpath
            fullPathAssemblies << testAssemblyRealPath
        end
    
        cmd.command = @dotCoverRealPath
        cmd.parameters = [
            "cover",
            "/AnalyseTargetArguments=False",
            "/TargetExecutable=#{@xUnitRunnerRealPath}",
            "/TargetArguments=\"#{fullPathAssemblies.join ';'}\"",
            "/Output=#{@testResultsRealPath}/coverage.dcvr"
            ]
    end
    
    task :coverageServiceMessage do |t|
        puts "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='#{@testResultsRealPath}/coverage.dcvr']"
    end
    

    Many thanks to @AnthonyMastrean as he showed me some really nice little ruby tricks and how I should be structuring my rake file properly.