Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild 2010 - how to publish web app to a specific location (nant)?

I'm trying to get MSBuild 2010 to publish a web app to a specific location. I can get it to publish the deployment package to a particular path, but the deployment package then adds its own path that changes.

For example: if I tell it to publish to C:\dev\build\Output\Debug then the actual web files end up at C:\dev\build\Output\Debug\Archive\Content\C_C\code\app\Source\ControllersViews\obj\Debug\Package\PackageTmp And the C_C part of the path changes (not sure how it chooses this part of the path).

This means I can't just script a copy from the publish location.

I'm using this nant/msbuild command at the moment:

  <target name="compile" description="Compiles">
<msbuild project="${name}.sln">

  <property name="Platform" value="Any CPU"/>
  <property name="Configuration" value="Debug"/>
  <property name="DeployOnBuild" value="true"/>
  <property name="DeployTarget" value="Package"/>
  <property name="PackageLocation" value="C:\dev\build\Output\Debug\"/>
  <property name="AutoParameterizationWebConfigConnectionStrings" value="false"/>
  <property name="PackageAsSingleFile" value="false"/>

</msbuild>

Any ideas on how to get it to send the web files directly to a specific location?

like image 460
Mr. Flibble Avatar asked May 28 '10 11:05

Mr. Flibble


People also ask

How do I publish a solution using MSBuild?

MSBuild supports targeting a single project while building the solution. You do this by putting the project name in the Target parameter. Note that this is the visual name of the project you specify in the solution (not necessarily the same as the name of the . csproj file).

What is DeployOnBuild?

"DeployOnBuild" tells msbuild that this web project needs to be packaged/deployed as part of the build. "WebPublishMethod" ensures we are just creating a deployment package. There are other options like publishing to the file system or elsewhere using MSDeploy.


2 Answers

msbuild /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Release;_PackageTempDir=C:\temp\somelocation;AutoParameterizationWebConfigConnectionStrings=false MyProject.csproj

Corresponding NAnt script:

<msbuild project="MyProject.csproj" target="PipelinePreDeployCopyAllFilesToOneFolder">
  <property name="Configuration" value="Release" />
  <property name="_PackageTempDir" value="C:\temp\somelocation" />
  <property name="AutoParameterizationWebConfigConnectionStrings" value="false" />
</msbuild>

References

  • Simulating "Publish to folder" Functionality in Visual Studio 2010
  • Team Build + Web Deployment + Web Deploy + VS 2010 = Goodness

See also Team Build: Publish locally using MSDeploy

like image 78
Pavel Chuchuva Avatar answered Oct 26 '22 13:10

Pavel Chuchuva


If you are using a VS2010 web application (as opposed to a web site project), consider setting up the Package/Publish Web settings in your project and building the 'Project' target in your nant script.

Lots of juicy msdeploy goodness and background here: http://www.hanselman.com/blog/WebDeploymentMadeAwesomeIfYoureUsingXCopyYoureDoingItWrong.aspx

In my nant scripts, I run the following msbuild commands:

    <if  test="${property::exists('basename')}">
        <exec program="${msbuild.location}" workingdir="${project::get-base-directory()}">
            <arg value="/p:Configuration=${configuration}" />
            <arg value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,${msbuild.logger.dll}" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="/noconsolelogger" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="${basename}.sln"/>
        </exec>
    </if>

...

    <if  test="${property::exists('basename')}">
        <exec program="${msbuild.location}" workingdir="${project::get-base-directory()}\${basename}">
            <arg value="/p:Configuration=${configuration}" />
            <arg value="/t:Package" />
            <arg value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,${msbuild.logger.dll}" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="/noconsolelogger" if="${nunit.formatter.type == 'Xml'}"/>
            <arg value="${basename}.csproj"/>
        </exec>
    </if>

My basename nant variable gives the name of both the VS solution file (.sln) and the project file (.csproj) for the web application. I happen to prefer the zip-file deployment as shown in my project settings:

Sample Package Settings for Deployment of Web Application

There is one additional quirk. If you install MSDeploy version 2.0 on the target machine, the .deploy.cmd file must be edited to change the MSDeploy version number as follows:

Change

  for /F "usebackq tokens=2*" %%i  in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1" /v InstallPath`) do (

To

  for /F "usebackq tokens=2*" %%i  in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\2" /v InstallPath`) do (
like image 27
randomfactor Avatar answered Oct 26 '22 12:10

randomfactor