从msbuild批处理目录属性中删除结尾的反斜杠 [英] Remove trailing backslash from msbuild batching Directory property
问题描述
我正在尝试使msbuild脚本中的exec任务正常工作,但发现了一个非常烦人的问题. exec命令很不错,除了我正在运行的进程(Ncover.Console.exe)无法在目录名末尾处理反斜杠.
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" />
但这失败了(注意"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
"%(TestAssemblies.RootDir)%(TestAssemblies.Directory)" />
所以我的问题是如何删除这个令人讨厌的尾随反斜杠?
So my question is how can I remove this pesky trailing backslash?
谢谢.
推荐答案
如果您使用的是MSBuild 4.0,则可以使用Amir指出的属性函数,如下所示:
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 "%(TestAssemblies.RootDir)$(TestAssembliesDirectory.TrimEnd('\'))"" />
这篇关于从msbuild批处理目录属性中删除结尾的反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!