TargetArguments with quotes (escape character?)

Hi,

I am running dotCover on the command line from msbuild and have run into a problem with target arguments with quotes. I can't seem to find the escape character for having quotes within the quoted target arguments.

For example if the command is
"C:\Program Files (x86)\JetBrains\dotCover\v2.0\Bin\dotCover.exe" a /ReportType=HTML /Filters="+:*;-:Gallio*;-:MbUnit*;-:*Test*;-:Company.*" /Output="C:\Product\Output\Reports\CodeCoverage.html" /TargetExecutable="C:\Product\Build\Gallio\Gallio.echo.exe" /TargetArguments="/filter:""exclude Category: Slow exclude Category: Database exclude Category: Stable exclude Category: Weekend"" /report-directory:""C:\Product\Output\Reports\."" /v:Verbose /report-name-format:TestResults /report-type:Xml ""C:\Product\Output\Product.Tests.dll"" ""C:\Product\Output\Product.Web.Tests.dll"""


So to break it down this is dotcover and its arguments:
"C:\Program Files (x86)\JetBrains\dotCover\v2.0\Bin\dotCover.exe"
a /ReportType=HTML  /Filters="+:*;-:Gallio*;-:MbUnit*;-:*Test*;-:Company.*"  /Output="C:\Product\Output\Reports\CodeCoverage.html"

Which runs Gallio:
/TargetExecutable="C:\Product\Build\Gallio\Gallio.echo.exe"
With the following arguments:
/filter:"exclude Category: Slow exclude Category: Database exclude  Category: Stable exclude Category: Weekend" /report-directory:"C:\Product\Output\Reports\." /v:Verbose /report-name-format:TestResults /report-type:Xml "C:\Product\Output\Product.Tests.dll" "C:\Product\Output\Product.Web.Tests.dll"


I tried escaping it with double quotes, backslash quotes and just using single quotes but none worked. An interesting point is that it seemed to work with quotes on their own as long as I excluded /filter: for gallio (even if i had quotes in the /report-directory:"C:\Product\Output\Reports\." it still worked fine).
I tried /AnalyseTargetArguments=false too incase it was messing with escape characters but no combinations worked.

As a work around I currently save just the TargetArguments to an xml file which dotcover then runs as below (MSBuild file):

    <PropertyGroup>
      <dotCoverExe>$(MSBuildProgramFiles32)\JetBrains\dotCover\v2.0\Bin\dotCover.exe</dotCoverExe>
      <GallioExe>$(BuildPath)\Gallio\Gallio.echo.exe</GallioExe>
      <GallioArguments>/filter:"$(TestFilter)" /report-directory:"$(OutReportDir)." /v:Verbose /report-name-format:$(TestSetName)TestResults /report-type:Xml @(AnalysisTestAssemblies->'"$(OutDir)%(Filename)%(Extension)"', ' ')</GallioArguments>
      <dotCoverFilter>+:*;-:Gallio*;-:MbUnit*;-:*Test*</dotCoverFilter>
      <dotCoverArguments>a /ReportType=HTML /Filters="$(dotCoverFilter)" /Output=&quot;$(OutReportDir)CodeCoverage.html&quot; /TargetExecutable=&quot;$(GallioExe)&quot; /AnalyseTargetArguments=false $(OutDir)CodeCoverageArguments.xml</dotCoverArguments>
      <UseCodeCoverage Condition="'$(UseCodeCoverage)' == '' and Exists('$(dotCoverExe)')">true</UseCodeCoverage>
    </PropertyGroup>

    <!-- Work around because target arguments require quotes in them. -->
    <ItemGroup>
      <LineText Include="&lt;AnalyseParams&gt;&lt;TargetArguments&gt;$(GallioArguments)&lt;/TargetArguments&gt;&lt;/AnalyseParams&gt;" />
    </ItemGroup>
    
    <WriteLinesToFile
         File="$(OutDir)CodeCoverageArguments.xml"
         Lines="@(LineText)"
         Overwrite="true" />

    <Exec
      Condition="'$(UseCodeCoverage)' == 'true'"
      IgnoreExitCode="true"
      Command="&quot;$(dotCoverExe)&quot; $(dotCoverArguments)"/>


But it is not a very nice work around! Obviously having an MSBuild task would fix this problem (I could pass in my string to TargetArguments) but until then does anyone see what I am doing wrong?

Cheers.

2 comments

Hi Seravy,

I tried to reproduce your issue and escaping with backslashes works fine for me. Please see the example below.

<PropertyGroup>
    <dotCoverExe>$(MSBuildProgramFiles32)\JetBrains\dotCover\v2.0\Bin\dotCover.exe</dotCoverExe>
    <GallioExe>C:\Program Files\Gallio\Bin\Gallio.echo.exe</GallioExe>
    <GallioArguments>/filter:\&quot;exclude Category: Slow exclude Category: Database\&quot; /report-directory:\&quot;C:\Product\Output\Reports\.\&quot; /v:Verbose /report-name-format:TestResults /report-type:Xml \&quot;C:\Product\Output\Product.Tests.dll\&quot;</GallioArguments>
    <dotCoverFilter>+:*;-:Gallio*;-:MbUnit*;-:*Test*</dotCoverFilter>
    <dotCoverArguments>a /ReportType=HTML /Filters=&quot;$(dotCoverFilter)&quot; /Output=&quot;C:\CodeCoverage.html&quot; /TargetExecutable=&quot;$(GallioExe)&quot; /TargetArguments=&quot;$(GallioArguments)&quot;</dotCoverArguments>
</PropertyGroup>

<Target Name="TargetName">
    <Exec IgnoreExitCode="true" Command="&quot;$(dotCoverExe)&quot; $(dotCoverArguments)"/>
</Target>

Please let me know whether it solves the problem.
Regards.

0

How confusing! The problem must have been something else, It appears to work fine now.

Thanks so much for your time, it is much cleaner this way.

0

Please sign in to leave a comment.