Publish your ASP. NET application using MSBuild Auto-compilation

Source: Internet
Author: User

This article describes how to use MSBuild to automatically compile and publish your ASP. More suitable for daily compilation. Usually we use the IDE (Visual Studio) to compile and publish the ASP, which requires manual action if the steps are cumbersome and error-prone. The same work can be done automatically by MSBuild, which is a Visual Studio compilation tool, provided with the. NET framework, and can typically be%systemdrive% \windows\microsoft.net\framework\v3.5find. For more information about MSBuild See Msdn:msbuild Overview Here's an example of how MSBuild does this. Download the sample here: Msbuilddemo unzip the sample file into a new directory, Where MSBuildDemo.sln is a sample project, this sample project includes a class library project ref, a Web application Engineering WebApp and a website website. and dailybuild\ DailyBuild.sln, which we created for MSBuild, contains configuration information for MSBuild compilation and publishing, including compilation scenarios (release), site publishing settings, and so on. Now try, double-click Dailybuild\dailybuild.bat, See if you can automatically compile and publish WebApp to webapppublished, compile and publish website to websitepublished directory?Dailybuild.bat, the main command is: C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe Dailybuild.xml/T:main @DailyBuild. RSP where Dailybuild.xml stores a series of MSBuild tasks (for information about MSBuild tasks, see Msdn:msbuild task Reference), MSBuild compiles and publishes your programs by performing a series of tasks./T:main Specifies the entry point for MSBuild, which explains where MSBuild should start (and later). @DailyBuild. RSP Specifies a response file for MSBuild (in order to avoid repeatedly entering the same command switch, Place each line of these switches in a response file instead). The main part is dailybuild.xml:1<project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">2<PropertyGroup>3<solutionroot&gt, .... </SolutionRoot>4<webappoutput&gt, .... \webapppublished</webappoutput>5<websiteoutput&gt, .... \websitepublished</websiteoutput>6</PropertyGroup>7 8<target name="getlatest">9<PropertyGroup>Ten<TFServer>$/PO</TFServer> One<WorkspacePath>D:\WorkCopies\PO\src\trunk</WorkspacePath> A<TFCommand>D:\Programs\VS9\Common7\IDE\tf.exe</TFCommand> -</PropertyGroup> - the<Exec -Command="$ (Tfcommand) history $ (tfserver)/version:t/noprompt/recursive/stopafter:1/format:detailed 1>dailybuild\ Msbuild\latestchangeset.txt" -workingdirectory="$ (solutionroot)" -Continueonerror="true"/> + -<Exec +Command="$ (tfcommand) Get" Aworkingdirectory="$ (Workspacepath)" atContinueonerror="true"/> -         -</Target> - -<target name="Build"> -<removedir directories="$ (webappoutput)"Continueonerror="false"/> in<makedir directories="$ (webappoutput)"Continueonerror="false"/> -<removedir directories="$ (websiteoutput)"Continueonerror="false"/> to<makedir directories="$ (websiteoutput)"Continueonerror="false"/> + -<MSBuild theprojects="$ (solutionroot) \dailybuild\dailybuild.sln" *Continueonerror="false" $targets="Rebuild"Panax Notoginsengproperties="Configuration=release"> -</MSBuild> the</Target> + A<target name="Cleanupafterbuild"dependsontargets="Build"> the<delete files="$ (webappoutput) \bin\*.pdb"Continueonerror="true"/> +<Delete -condition="Exists (' $ (webappoutput) \BFL. MSBuildDemo.WebApp.csproj ')" $files="$ (webappoutput) \BFL. MSBuildDemo.WebApp.csproj" $ContinueOnError ="true"/> -<Delete -condition="Exists (' $ (webappoutput) \BFL. MSBuildDemo.WebApp.csproj.user ')" thefiles="$ (webappoutput) \BFL. MSBuildDemo.WebApp.csproj.user" -ContinueOnError ="true"/>Wuyi<Delete thecondition="Exists (' $ (webappoutput) \BFL. MSBuildDemo.WebApp.Publish.xml ')" -files="$ (webappoutput) \BFL. MSBuildDemo.WebApp.Publish.xml" WuContinueOnError ="true"/> -<RemoveDir Aboutcondition="Exists (' $ (webappoutput) \obj ')" $directories="$ (webappoutput) \obj" -ContinueOnError ="true"/> - -<delete files="$ (websiteoutput) \bin\*.pdb"Continueonerror="true"/> A</Target> + the<target name="Main"> -<calltarget targets="getlatest"Continueonerror="false"/> $<calltarget targets="Cleanupafterbuild"/> the</Target> the</Project>where PropertyGroup defines some global variables, you can use it in this file in the form of $ (variable name). Target is equivalent to a function or method, the entry point that we defined for MSBuild in the command above/T:main is a target.target that consists of a set of CallTarget or MSBuild tasks that define the DependsOnTargets property for the target element to ensure that the current target is executed The target specified by DependsOnTargets is called first. The target name of Dailybuild.xml shows that the first thing we do in the example is Getlatest, which ensures that the latest version of the code is obtained before compiling. We do this by performing two exec tasks in getlatest. Here I use TFS (Team Foundation Server) and you can replace the equivalent VSS, CVS or SVN commands with your actual situation. The next thing to do is build, We invoke the MSBuild task to compile the DailyBuild.sln solution and publish the WebApp and website based on the settings in the solution. Finally, based on the experience of multiple auto-compiling, I added cleanupafterbuild to remove unnecessary files. In addition, you can refer to this link msbuild Community tasks to add more tasks to MSBuild.

Publish your ASP. NET application using MSBuild Auto-compilation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.