NAnt MVC publishes website

Problem . I want to gracefully publish an MVC website with NAnt.

Simple no? Wrong ... Here are some of the stackoverflow resources that I have been looking at. Each of them has a problem ...

Stackoverflow 1: Publish WebApplication with NAnt

The result of this was that web.config was not being converted, and additional files appeared in the box that did not assume that they were similar to the entity.dll.config file.

Stackoverflow 2: VS2008 Publish Website Replication from the Command Line

This one will do the same as the previous solution, except that it is even worse ... it will copy EVERYTHING from my project and upload it to the publication folder ... no joke!

Stackoverflow 3: MSBuild Script and VS2010 publish Web.config transform application

The decision is built on top of Stackoverflow 1, but is pure MsBuild xml, not NAnt xml. It also only captures Webconfig and, nevertheless, leaves these random files that appear. There is another solution (not accepted) that gives pattersonc, which is very, very close to the correct one, but the connection strings in the web.config file are in a dummy limbo state, leaving you another bad web.config

Needless to say, it was 3-4 days, 10+ different StackOverFlow answers and no silver bullet ... Is there a simple solution? Should I commit some cardinal sin and create some terribly spoiled NAnt Script to achieve the correct publication results that VS2010 delivers so beautifully?

+6
source share
2 answers

Ok, I figured this out after I asked about this blog, http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx

In step 4, it shows the arg command line that I have not seen before, / T: TransformWebConfig

Unfortunately, this alone does not solve the problem. It does the conversion, but the conversion is in obj / Release / TransformWebConfig / transform / Web.config (obj / Release or obj / Debug or obj / YourTranformName).

So, to finally get a decent solution, this is what I had 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/" /> </exec> <delete dir="${path.build}/temp" failonerror="true"/> <delete file="${path.build}/ProjectBuild/Web.config" failonerror="true"/> <delete file="${path.build}/ProjectBuild/Web.Debug.config" failonerror="true"/> <delete file="${path.build}/ProjectBuild/Web.Release.config" failonerror="true"/> <copy file="${path.sourceCode}/ProjectFolder/obj/Release/TransformWebConfig/transformed/Web.config" tofile="${path.build}/ProjectBuild/Web.config" /> 

Note that OutDir is different from WebProjectOutputDir. That's why:

  • OutDir gives you everything in the project "solution."
  • WebProjectOutputDir gives you a bare minimum for a web project project (i.e. not the whole solution).

Of the other projects in the solution using OutDir, a lot of additional baggage appeared that we do not need, so we just sent OutDir to a temporary folder and deleted it, as you can see in the above steps. By the way, OutDir is absolutely necessary. The assembly will not work if you remove it. WebProjectOutputDir seems to work outside of OutDir.

There is only one minor flaw in this entire setup. The bin library is missing many pdb files. The only pdb copied was that of a web project.

If anyone finds a one-step solution with MSBuild, submit it: P Although this is a good solution, it is still only 99.9999% perfect and very similar to the ones listed above. I am sure that there will be some small nuance or missing step.

+6
source

After checking your solution, I came across another solution fooobar.com/questions/34302 / ...

I revised your answer to use the _WPPCopyWebApplication target instead:

 <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:_WPPCopyWebApplication" /> <arg value="/t:TransformWebConfig" /> <arg value="/p:OutDir=${path.buildFromProject}/temp/" /> <arg value="/p:WebProjectOutputDir=${path.buildFromProject}/ProjectBuild/" /> </exec> 

After testing, I no longer need to delete configs and copy the converted files.

+3
source

Source: https://habr.com/ru/post/886437/


All Articles