2
votes

Typically when doing a build script for C# I just include **/*.cs for each project/dll to build. However I now have a situation where I have some .cs files which are not part of the project but live in that directory (they are there for reference purposes from another library). There are not linked in the .csproj file so the VS build works fine but the nant build does not.

Does anyone know if there's a nice easy way of pulling the .cs entries out of the relevant .csproj file and using that as the list of source files to build rather than using a general wildcard match.

Thanks in advance.

5

5 Answers

4
votes

Any particular reason you don't want to use msbuild just for the C# build bit? That's what I do for my Protocol Buffers port, and it works well. It does require nant-contrib, but that's not much of a hardship.

That way you know you only need to get one thing working, and know it'll be built the same way.

You can have a look at my ProtoBuf port build file here, for inspiration. The obvious downside is Mono support, but I believe xBuild is improving...

3
votes

nant has support for automatically building VS solutions, including csproj files, using a <solution> task.

The latest supported solution format is VS 2003.

3
votes

Nantcontrib includes an msbuild task - you can use this to build both projects and solutions. Here's an example of it in practice: http://web.archive.org/web/20100913051600/http://codebetter.com/blogs/jeffrey.palermo/archive/2006/08/12/148248.aspx

2
votes

You could build the project using MSBuild via an Exec task instead of invoking compiler directly e.g. msbuild project.csproj.

1
votes

Using MSBuild is a great idea. However, if there are any orphaned files (.cs files not in .csproj), aspnet_compile.exe will sometimes fail. To get around this I wrote the following to remove all *.cs files that are not included in the .csproj. So far so good, any feedback is appreciated.

<project>
 <foreach item="File" property="csprojFile">
 <in>
  <items>
   <include name="source/**/*.csproj" />
  </items>
 </in>
 <do>
  <property name="currentFolder" value="${directory::get-current-directory()}" />
  <property name="csprojParentFolder" value="${directory::get-parent-directory(csprojFile)}" />

  <foreach item="File" property="csFile">
   <in>
    <items>
     <include name="${csprojParentFolder}/**/*.cs"/>
    </items>
   </in>
   <do>

    <property name="csFileRelativePath" value="${string::replace(csFile, csprojParentFolder + '\', '')}" />
    <loadfile property="projFile" file="${csprojFile}" />
    <if test="${not string::contains(projFile, csFileRelativePath)}">
     <echo message="${csprojFile}:  | Missing: ${csFileRelativePath}" />
     <!-- <delete file="${csprojParentFolder + '\' + csFileRelativePath}" /> -->
    </if>
   </do>
  </foreach>

 </do>
 </foreach>
</project>