2009-04-16 5 views
6

저는 NAnt를 사용하기 시작했습니다. 튜토리얼에서 일하고 있었고 빌드 할 때 내 솔루션을 정리할 대상을 설정하려고했습니다.NAnt에서 작업 디렉토리를 설정하는 방법은 무엇입니까?

  • 솔루션 폴더
    • 프로젝트 폴더
    • 프로젝트 폴더
    • 도구 폴더
      • 은 NAnt 폴더
  • 를 다음과 같이 내 비주얼 스튜디오 솔루션 구조는

NAnt .exe 파일은 Tools/NAnt 폴더에 있습니다. 내 .build 파일도 여기에 있습니다. 여기 내 .build 파일입니다

<?xml version="1.0" encoding="utf-8" ?> 
<project name="NAntTest" default="build" xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd"> 
    <property name="solution.file.name" value="NAntTest.sln" /> 
    <property name="project.config" value="debug" /> 

    <target name="build" depends="clean.source" /> 

    <target name="clean.source"> 
    <exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe" 
      commandline="${solution.file.name} /t:Clean /p:Configuration=${project.config} /v:q" 
      workingdir="."/> 
    </target> 

</project> 

이 내가 다음하고있는 예는 포맷 한 방법이다. 이 빌드를 실행하려고하면 프로젝트 파일이 존재하지 않는다는 오류가 발생합니다. clean.source 대상에서 workingdir 특성을 기본 솔루션 폴더의 하드 코딩 된 경로로 바꾸면 스크립트가 올바르게 컴파일되고 실행됩니다. 분명히,이 프로젝트를 어디든지 옮겨야한다면 이식성에 이상적이지 않습니다.

기본 작업 디렉토리를 보려면 NAnt를 어떻게 얻습니까?

답변

7

내 솔루션은 항상 빌드 파일을 배치하는 것이 좋습니다. 그러면 빌드 파일의 모든 상대 경로가 솔루션의 상대 경로와 동일하게됩니다.

+0

솔루션 디렉토리로 이동하면됩니다. 도와 주셔서 감사합니다! –

+0

흠, downvote? 왜? –

+1

그래도 효과가있을 것입니다.하지만 충고는 정확하지 않습니다. 그냥 basedir을 적절하게 설정하십시오. (Btw, 내가 downvoted되지 않았습니다.) – BrainSlugs83

2

프로젝트 노드의 basedir 속성을 설정할 수 있습니다. 이로 인해 문제가 해결 될 수 있습니다.

+1

(즉 ".. \ .."). – BrainSlugs83

+0

이것은 상대 경로를 사용하는 주석과 함께 정답입니다. –

1

nant의 verbose 속성을 exec task으로 설정하면 생성 된 정확한 명령 행이 출력됩니다. 확실하지 않은 특정 문제가 msbuild 실행에 관한 - 나는 nantcontrib msbuild task 대신 사용하고 있습니다.

7

는이 현재 디렉토리를 변경할 수있는 기능을 내장하지 않습니다,하지만 당신은 스크립트 블록에 하나 만들 수 있습니다 : 당신은 당신의 스크립트 나 코드에서 현재 디렉토리에 의존하지 않도록해야합니다, 물론

<target name="foo"> 
    <echo message="Current directory set to ${directory::set-current-directory('C:')}"/> 
    <echo message="Current directory is now ${directory::get-current-directory()}"/> 
    </target> 

    <script language="C#" prefix="directory"> 
    <code><![CDATA[ 
    [Function("set-current-directory")] 
    public static string SetCurrentDirectory(string path) 
    { 
     System.IO.Directory.SetCurrentDirectory(path); 
     return path; 
    } 
    ]]></code> 
    </script> 

을 .

0

exec 요소에 정의 할 수있는 workingdir 속성이 있습니다.

documentation에 따르면, workingdir은 "명령이 실행될 디렉토리"를 나타냅니다. 대신 함수의 작업으로

0

:

<?xml version="1.0"?> 
<project name="test" default="build"> 
    <script language="C#" prefix="path" > 
     <code> 
      <![CDATA[ 
      [TaskName("set-current-directory")] 
      public class SetCurrentDirectory : Task { 
       private string _path; 

       [TaskAttribute("path", Required=true)] 
       public string Path { 
        get { return _path; } 
        set { _path = value; } 
       } 

       protected override void ExecuteTask() { 
        System.IO.Directory.SetCurrentDirectory(_path);; 
       } 
      } 
      ]]> 
     </code> 
    </script> 

    <target name="build"> 
     <set-current-directory path="c:\Program Files" /> 
     <echo message="${directory::get-current-directory()}" /> 
    </target> 
</project> 

출력 : 당신은 아마 상대 경로를 사용하여 기본 디렉토리를 설정해야합니다

$ nant 

build: 

    [echo] c:\Program Files 
관련 문제