Problem: I wish to stylishly publish an MVC website with NAnt.

Simple no? Wrong... Here are the stackoverflow assets I have checked out. Every one of them comes with an problem...

Stackoverflow 1: Publish WebApplication using NAnt

Caused by that one could be that the web.config wasn't being changed and extra files were turning up within the bin that were not suppose to love the entity.dll.config of the things!

Stackoverflow 2: Replicate VS2008 "Publish Web Site" from command line

That one is going to do just like the prior solution except it's a whole lot worse... it'll copy From my project and dump it in to the publish folder... serious!

Stackoverflow 3: MSBuild Script and VS2010 publish apply Web.config Transform

The recognized solution develops surface of Stackoverflow 1, but is pure MsBuild xml and never NAnt xml. Additionally, it only fixes the Webconfig and thus still leaves individuals random files that demonstrate up. There's also another solution (not recognized) that pattersonc gives, that is very, not far from correct however the connection strings within the web.config have been in a bogus limbo condition, departing you with another bad web.config

Obviously it has been 3-4 days, 10+ different StackOverFlow solutions with no silver bullet... Can there be very difficult solution? Can I commit some cardinal sin and make some horribly screwed up NAnt script to offer the correct publish results that VS2010 provides so nicely?

Okay I believed it after chancing about this blog,

In step four he shows an order line arg I've not seen before, /t:TransformWebConfig

Regrettably, this one thing doesn't solve the issue. It will carry out the transform however the transform can be found in obj/Release/TransformWebConfig/changed/Web.config (obj/Release or obj/Debug or obj/YourTranformName).

To finally obtain a decent solution this is exactly what I needed to do.

<exec program="${exec.msbuild}" failonerror="true">
    <arg value="${path.sourceCode}/ProjectFolder/Project.csproj" />
    <arg value="/p:Configuration=Release" />
    <arg value="/t:ResolveReferences" />
    <arg value="/t:_CopyWebApplication" />
    <arg value="/t:TransformWebConfig" />
    <arg value="/p:OutDir=${path.buildFromProject}/temp/" />
    <arg value="/p:WebProjectOutputDir=${path.buildFromProject}/ProjectBuild/" />

<delete dir="${}/temp" failonerror="true"/>
<delete file="${}/ProjectBuild/Web.config" failonerror="true"/>
<delete file="${}/ProjectBuild/Web.Debug.config" failonerror="true"/>
<delete file="${}/ProjectBuild/Web.Release.config" failonerror="true"/>
<copy file="${path.sourceCode}/ProjectFolder/obj/Release/TransformWebConfig/transformed/Web.config" tofile="${}/ProjectBuild/Web.config" />

Observe that the OutDir is different then the WebProjectOutputDir. Because of this , why:

  • OutDir provides you with my way through the project "solution".
  • WebProjectOutputDir provides you with the minimum for that web "project" (i.e. not the whole solution).

Procuring baggage was coming over using their company projects within the solution using OutDir that people did not want therefore we just sent OutDir to some temp folder and erased as you can tell within the steps above. OutDir is completely needed incidentally. The build won't work should you take it off. Appears that WebProjectOutputDir works from OutDir.

There's just one minor flaw with this particular entire setup. Lots of pdb files are missing in the bin library. The only real pdb replicated over was the main one on the internet project.

If anybody ever finds a 1 step solution with MSBuild for this please publish it : P Although this is an excellent solution it's still only 99.9999% perfect and similar to the ones in the above list I am sure there's likely to be some little nuance or step skipped.