views:

281

answers:

2

In my Nant file I've got (paths shortened):

<echo message="#### TARGET - compile ####"/>
<echo message=""/>
<echo message="Build Directory is ${build.dir}" />

<exec program="${framework}\msbuild.exe"
      commandline="..\src\Solution.sln /m /t:Clean /p:Configuration=Release" />

<exec program="${framework}\msbuild.exe"
      commandline="..\src\Solution.sln /m /t:Rebuild  /p:Configuration=Release" />

<exec program="${framework}\msbuild.exe"
      commandline="..\src\Solution.sln /m /t:TransformWebConfig /p:Configuration=Release" />

Which results in:

Build FAILED.       "C:\..\src\Solution.sln" (TransformWebConfig target) (1) ->         C:\..\src\Solution.sln.metaproj : error MSB4057: The target "TransformWebConfig" does not exist in the project. [C:\..\src\Solution.sln]    0 Warning(s)    1 Error(s)Time Elapsed 00:00:00.05

The solution and associated projects are all VS2010 and the Web Application even has the correct reference in the .csproj:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

Shouldn't this just work?

+2  A: 

You can't, it isn't a problem specific to NAnt, you just can't call TransformWebConfig on a solution file.

Solutions :

  • Call it on your project file :

     <exec program="${framework}\msbuild.exe"
           commandline="..\src\WebApp\WebApp.csproj /m /t:TransformWebConfig /p:Configuration=Release" />
    
  • Override the AfterBuild target in your project file to call TransformWebConfig :

    <Target Name="AfterBuild">
      <CallTarget Targets="TransformWebConfig"/>
    </Target>
    
madgnome
A: 

I couldn't get it working with the TransformWebConfig option nor the AfterBuild Target, However, this post was the answer for me. In short, this is what my "build" target looks like in Nant:

<target name="build" description="Compiles/Builds the Solution">
<echo message="Building..." />
<property name="build.configuration" value="Release" />

<msbuild project="${path::combine(staging.project,'_solutions\mySolutionName.sln')}" verbosity="minimal" failonerror="true" verbose="false">
    <arg value="/p:Configuration=${build.configuration};OutputPath=${path::combine(staging.output,'bin')}" />
    <arg value="/p:UseWPP_CopyWebApplication=True" />
    <arg value="/p:PipelineDependsOnBuild=False" />
    <arg value="/p:WebProjectOutputDir=${staging.output}\" />
    <arg value="/t:Rebuild" />
    <arg value="/nologo" />
</msbuild>
<echo message="Building finished..." />

All the files needed for the website to run are copied into the specified "WebProjectOutputDir" property, including the web.Config with the transformations applied. it worked like a charm :)

-Diego

Diego C.