Remove trailing backslash from msbuild batching Directory property

◇◆丶佛笑我妖孽 提交于 2019-12-19 12:52:46

问题


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.


回答1:


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;" />


来源:https://stackoverflow.com/questions/5321959/remove-trailing-backslash-from-msbuild-batching-directory-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!