15

I'm trying to get an exec task inside an msbuild script to work and have found a very annoying issue. The exec command is sweet except that the process I'm running (Ncover.Console.exe) can't handle a backslash at the end of a directory name.

To illustrate with a snipped example, the following works:

<exec command="NCover.Console.exe nunit-console.exe some.dll [snip] //w c:\out" />

But this fails (note the slash at the end of "c:\out"):

<exec command="NCover.Console.exe nunit-console.exe some.dll [snip] //w c:\out\" />

The reason I can't simply delete the trailing backslash is that the value is read using batching. So in the same snipped as above, it actually looks like this:

<exec command="NCover.Console.exe nunit-console.exe some.dll [snip] //w 
&quot;%(TestAssemblies.RootDir)%(TestAssemblies.Directory)&quot; />

So my question is how can I remove this pesky trailing backslash?

Thanks in advance.

Ashby
  • 583
  • 9
  • 20
  • 1
    You can use batching and still remove the backslash using transformations or property functions. Is there any special reason you don't want to use these? – Amir Gonnen Mar 16 '11 at 07:27
  • Hi Amir. Can you please demonstrate how I can use transformations or property functions in my case? Please use the reply button so I can credit you with the answer and your response appears in search results. Thanks. – Ashby Mar 17 '11 at 03:39
  • 1
    In Danere's answer you can see an example of how to do this with [property functions](http://msdn.microsoft.com/en-us/library/dd633440.aspx). (It is probably not possible with [transforms](http://msdn.microsoft.com/en-us/library/ms171476.aspx) because you can only add characters there) – Amir Gonnen Mar 17 '11 at 09:41

1 Answers1

24

If you are using MSBuild 4.0 you can use property functions as pointed out by Amir, like this:

<PropertyGroup>
  <TestAssembliesDirectory>%(TestAssemblies.Directory)</TestAssembliesDirectory>
</PropertyGroup>
<exec command="NCover.Console.exe nunit-console.exe some.dll [snip] //w &quot;%(TestAssemblies.RootDir)$(TestAssembliesDirectory.TrimEnd('\'))&quot;" />
Dan Nolan
  • 4,733
  • 2
  • 25
  • 27
  • Hi Danere. Unfortunately we're using msbuild 3.5 which doesn't allow property functions. Can you think of any other method for doing this? I've investigated the MSBuildHelper class but to no avail - perhaps I'll have to write a custom task or experiment with the msbuild community task RegexReplace function. – Ashby Mar 17 '11 at 22:33
  • 2
    FYI my resolution was to replace that part of the command altogether with a static property. I would've been looking into using either a – Ashby Mar 17 '11 at 23:30