Building .net 4.0 with nant in TeamCity

Hi Guys

Using TeamCity 5.1.2, I am able to build my .net 4 application successfully using Visual Studio (sln) build runner, and specifying Visual Studio 2010.

I am also able to successfully build the application running a Nant build file directly on the server that TeamCity is running on,

so I know Nant is configured correctly to use .net 4.0.

But if I try using the Nant build runner in TeamCity, and set the Target Framework as unspecified (as this option only goes up to .net3.5),

I receive the following error which leads me to believe that it’s using .net 3.5 to compile the application

c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(2341, 9): error MSB3188: Assembly ‘…' must be strong signed in order to be marked as a prerequisite.

Is there something specific i need to do to TeamCity in order to use Nant to compile .net 4.0?


Please add tools-version="4.0" attribute to <msbuild> task.


Please note, I've mispelled attribute name. It should be 'tools-version'


Excellent my task now looks like, and it works.

        <msbuild verbose="true" verbosity="Detailed" failonerror="true" project="${projectfile}" tools-version="4.0">
            <property name="Configuration" value="Release"/>

Thanks so much for your help!


Do you have tools-version specified in the msbuild project file? I think to parse msbuild files to find tools version.


I am compiling and unit testing my code with NAnt in TeamCity 5.1.1.

I've set the NAnt "Target framework" option to "unspecified" and added "-t:net-4.0" to the command line parameters for NAnt. This is NAnt 0.90 with NAnt.exe.config modified to support the "net-4.0" target platform.

However I did indeed have some problems using the <msbuild /> task. My workaround was this:

<!--   If we're being run by TeamCity, use their NUnit launcher --> <if test="${property::exists('teamcity.dotnet.nunitlauncher2.0')}">   <!--     Currently, TeamCity messes up with .NET 4.0 projects containing resources   -->   <if test="${msbuild.version == 'net-4.0'}">     <exec       program="${msbuild.path}"       failonerror="true"       managed="true"     >       <arg file="${msbuild.project}" />       <arg value="/property:Configuration=${msbuild.configuration}" />       <arg value="/property:UNITTEST=true" if="${msbuild.unittest == 'true'}" />     </exec>   </if>   <if test="${not (msbuild.version == 'net-4.0')}">     <if test="${msbuild.version == 'net-3.5'}">       <property name="teamcity_dotnet_use_msbuild_v35" value="true" />     </if>     <msbuild       project="${msbuild.project}"       target="Build"     >       <arg value="/property:Configuration=${msbuild.configuration}" />       <arg value="/property:UNITTEST=true" if="${msbuild.unittest == 'true'}" />     </msbuild>   </if> </if>

If the NAnt script is not run by TeamCity, I invoke msbuild through the <exec /> task as well because the <msbuild /> task from NAntContrib didn't seem to use MSBuild 4.0 even with the net-4.0 tooling paths.

I haven't tried what Eugene suggested myself yet.

Please sign in to leave a comment.