开发者

Convert long name to short name in NANT?

I am working on a NANT build project to build a VS project. One of the build file has a property definition like this:

<property name="App.dir" 
  value ="${directory::get-current-directory()}\Source\App"/>

This property value has been used in many other places. For example:

<exec program=".\test.exe"  workingdir=".">
  <arg line="${App.dir}\project1\resources\res1.resx /arg2"/>

Here I need to use <arg line=...> instead of <arg value=...> is to pass specified 2 arguments to text.exe.

when I build this NANT project on another developer's machine, I got a build failure. Finally I found out that the ${App.dir} on that developer's machine is a path in long-form and there is a space in the path. As a result, the arguments to text.exe were actually 3 or more.

I am not sure if there is any way to convert the ${App.dir} path to short name with no spaces:

<property name="App.dir" value ="????"/>

where ???? is something to convert "${directory::get-current-directory()}\Source\App" to a path开发者_StackOverflow社区 name in a short-form. Is there any way to do that?

I am using NANT in Windows XP. In Unix/Cgywin, there is one function to get dos name:

cygpath::get-dos-path

Can I use this one in my NANT build file?


Use <arg value="">, from the NANT docs:

value - A single command-line argument; can contain space characters.


I think that I found two ways to resolve the issue. Instead of converting path to DOS path (8.3 name), I can use quotes around my arguments. The second method is the one as ovado recommened to use <arg value=.../> for a single argument value. Here is my test example. All the test files are in my C:\Test folder. First, I created a test bat:

@REM This is the content of Test.bat file.
@echo COMMAND PARAMETERS: %*
@echo FIRST PARAMETER: %1
@echo SECOND PARAMETER: %2
dir %1

Then I created a test build file (Test.Build)"

<project>
  <target name="Test" description="Test with one line" failonerror="true">
    <property name="App.dir" value ="C:\Program Files"/>
    <exec program="test.bat"  workingdir=".">
      <arg line='"${App.dir}\Microsoft*.*" ${App.dir}\test2 /test3' />
    </exec>
  </target>
  <target name="Test2" description="Test2 with values" failonerror="true">
    <property name="App.dir" value ="C:\Program Files"/>
    <exec program="test.bat"  workingdir=".">
      <arg value="${App.dir}\Microsoft*.*" />
      <arg value="${App.dir}\test2" />
      <arg value="/test3" />
    </exec>
  </target>
</project>

Here I used " to close my first argument in <arg ='"..."' .../>. Notice that I used single quote for my attribute line.

In this way, I run my build by NANT.EXE. I got the result as I expected:

C:\Test>NANT.exe -buildfile:test.build Test

Test:
   [exec] COMMAND PARAMETERS: "C:\Program Files\Microsoft*.*" C:\Program Files\test2 /test3
   [exec] FIRST PARAMETER: "C:\Program Files\Microsoft*.*"
   [exec] SECOND PARAMETER: C:\Program
   [exec] C:\Test\>dir "C:\Program Files\Microsoft*.*"
   [exec]  Volume in drive C has...
   ....

I got the same result with the alternative Test2,

C:\Test>NANT.exe -buildfile:test.build Test2
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜