Tag Archives: NAnt

NAnt sucks and Rake rocks

1 Feb

In these days I’m moving my build scripts from NAnt to Rake. The main reason for doing this is that I’m moving from external dsl to an internal dsl. Internal DSLs are often the most approachable form of DSLs to write. Unlike external DSLs you don’t need to learn about grammars and language parsing, unlike language workbenches you don’t need any special tools. With internal DSLs you work in your regular language environment.

This means that now I build my build scritps just with ruby. I believe this is a good way to learn this nice language. Rake in fact is nothing more that a Ruby library.

Getting started with Rake and .NET is very easy:

  • Download the Ruby for windows one click installer.
  • Install it
  • Create a file Rakefile.rb (type is text file)
  • Type:
    task :default => :build
    
    task :build => [:compile, :test, :deploy] 
    
    task :compile do
      params = '/t:Rebuild /nologo /v:m /p:Configuration=Release src\demo.sln'
      msbuid = 'C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\MSBuild.exe'
      sh "#{msbuid} #{params}" 
    end
    
    task :test do
     runner = 'tools\\Gallio\\Gallio.Echo.exe'
     assemblies = FileList["src/**/bin/Release/*.Fixture.exe"]
     extension = '' #'/e:TeamCityExtension,Gallio.TeamCityIntegration'
     sh "#{runner} #{assemblies} #{extension}"
    end
    
    task :deploy do
        sh "echo Task not yet implemented!"
    end
  • Open a command prompt (Start->Run->Cmd)

  • Type: cd c:\[my RakeFile.rb folder] (obviously put your own path in)

  • Type: rake
  • Done!

As you can see here above with rake there is no need to learn some crazy xml syntax. Whit this little script I compile my solution and run all unit tests. No need to write xml, only some ruby code.

Nothing more nothing less.

Technorati Tag: ,,,
Annunci

NAnt + NDepend.Console.exe and relative paths

5 Gen

If you read the documentation of NDepend.Console.exe you learn that relative paths are not supported. These remarks also apply to paths provided with options /InDirs /OutDir and /XslForReport.

Here you can see the result of a wrong line command

image

and here the result of a right line command

image

Unfortunately this is a problem for my solutions cause I need always relative path. My solution are continuous integrated using TeamCity and in my setup the build agent checks out sources in a random folder on the build agent machine (for eg. C:\BuildAgent\work\12724a65ddd4c6d0).

Here the Version Control Settings page of my project inside my TeamCity server where you can set the checkout directory.

image

Using relative path for me is a plus cause allow developers to freely decise the checkout project folder. For some of our customer this has been a project requirement.

Ok now you know why I need relative paths. Now I want to explain how I use NAnt + NDepend inside my continuous integrated solution. 

This is the target I use to run NDepend.Console.exe.

image

As you can see using the directory::get-current-directory I can build an absolute path at run-time. Maybe this result can be obtained using the built-in property  ${nant.project.basedir} but this is marked as deprecated so I prefer to use the directory::get-current-directory function.

Use NAnt to run mbunit tests using gallio

1 Dic

Gallio has a great build-in support for NAnt!
Unfortunately at the moment this is not well document so if you need to create a target to execute all tests inside an assembly you can write this xml fragment inside your NAnt project file:

<target name=”test” depends=”build”>
  <gallio
    result-property=”exitCode”
    failonerror=”false” >
    <runner-extension value=”TeamCityExtension,Gallio.TeamCityIntegration” />
    <assemblies>
      <!– Specify the tests assemblies –>
      <include name=”${src.dir}Data.Fixturebin${project.config}Data.Fixture.dll”/>
    </assemblies>
  </gallio>
  <fail if=”${exitCode != ‘0’}” >One or more tests failed. Please check the log for more details</fail>   
</target>

don’t forget to load Gallio NAnt Tasks before start with this line of xml

<loadtasks assembly=”.toolsGallioGallio.NAntTasks.dll” />

If you need more information you can take a look at comment in the source code here

Technorati Tag: ,,