Project management Practice "Five" automatic compile and publish Web sites Using Visual Studio with Source control System to build and publish website automatically "__web

Source: Internet
Author: User
Tags robocopy robocopy gui

In the previous Tutorial project management practice "three" daily builds "use Cruisecontrol.net and MSBuild", we explained how to work with Ccnet+msbuild from the dynamic compilation project, Today we'll explain how to use msbuild+webdeployment+robocopy to automatically compile and deploy ASP.net Web sites.
First, install the following three software:

1.msbuild.community.tasks Download:
Http://msbuildtasks.tigris.org/files/documents/3383/28296/MSBuild.Community.Tasks.msi

Source:
Http://msbuildtasks.tigris.org/files/documents/3383/36642/MSBuild.Community.Tasks.v1.2.0.306.zip

2.WebDeployment Download:

For VS2005
Http://download.microsoft.com/download/9/4/9/9496adc4-574e-4043-bb70-bc841e27f13c/WebDeploymentSetup.msi

For VS2008 [RTW]
Http://download.microsoft.com/download/9/4/9/9496adc4-574e-4043-bb70-bc841e27f13c/WebDeploymentSetup.msi

3.Utility Spotlight Robocopy GUI Download: "Download, after decompression installation, Vista does not install"
Http://download.microsoft.com/download/f/d/0/fd05def7-68a1-4f71-8546-25c359cc0842/UtilitySpotlight2006_11.exe

After the installation is complete, start today's tutorial.

We use the Startkit solution created in the previous tutorial as an example of the following structure:

Right-click on the Web project Startkit shown in the previous illustration, and then click Add Web Deployment Project ..., as in the following figure:

Pop up the form below and enter the name of the deployment project and the location where the project will be placed, as shown in the following figure:

After clicking the OK button, the solution is structured as follows:

Today we'll talk about the following two methods, like the steps above, starting here, the following steps are different.

Method One: Use Webdeployment to create a virtual directory

Advantages: Easy to use

Disadvantage: Not powerful enough to deploy to virtual directories only

Right-click on the deployment project and click on the property Pages in the menu, as shown below:

In the following form, click Complication on the left and enter the output path to the compiled Web site file in the text box under output folder on the right:

Then, click on the Deploment on the left and select the checkbox in front of Create an IIS virtual directory for the output folder on the right, in the following virtual directory Enter the name of the virtual directory in the text box under Name, Replace the checkbox in front of the existing virtual directory to determine whether it is selected, as shown in the following figure:

Click the OK button, compile the deployment project Startkit.csproj_deploy, after the success of the compilation, we open IIS, the default Web site can see the virtual directory Startkit. OK, it worked.

Method Two: Use Webdeployment+msbuild+robocopy

Advantages: Strong function

Disadvantage: Configuration is a bit troublesome

This method does not need to configure the property Pages, right click the Startkit.csproj_deploy project file directly, click Open Project file in the menu to open the deployment project files:

Modify the deployment project file for the following:

1 <!--Microsoft Visual Studio 2008 WEB deployment Project http://go.microsoft.com/fwlink/?LinkID=104956-->
2
3 < Project ToolsVersion = "3.5" DefaultTargets = "build" xmlns = "http://schemas.microsoft.com/developer/msbuild/2003 ">
4 < PropertyGroup >
5 < Configuration Condition = "' $ (Configuration) ' = = '" > Debug </Configuration >
6 < Platform Condition = "' $ (Platform) ' = = '" > AnyCPU </Platform >
7 < productversion > 9.0.21022 </productversion >
8 < schemaversion > 2.0 </schemaversion >
9 < ProjectGuid > {00000000-0000-0000-0000-000000000000} </projectguid >
< Sourcewebphysicalpath > ... /startkit </Sourcewebphysicalpath >
< Sourcewebproject > {96e1a089-3fbb-4909-94f6-172665994449}| Startkit/startkit.csproj </sourcewebproject >
< Sourcewebvirtualpath >/startkit.csproj </sourcewebvirtualpath >
< targetframeworkversion > v3.5 </targetframeworkversion >
< ProjectName > Startkit </ProjectName >
< Major > 1 </Major >
< Minor > 0 </Minor >
< Revision > 0 </Revision >
< Vssname > Ttzhang </vssname >
< Vsspassword > 123456 </vsspassword >
< ftpname > Anonymous </ftpname >
< FTPPassword > Anonymous </ftppassword >
< smtpservername > smtp.163.com </smtpservername >
< fromaddress > ttzhang@163.com </fromaddress >
< toaddress > zttc@163.com </toaddress >
< MailPassword > Testmail </mailpassword >
</PropertyGroup >
< PropertyGroup Condition = "' $ (Configuration) |$ (Platform) ' = = ' debug| AnyCPU ' ">
< DebugSymbols > True </debugsymbols >
< OutputPath >/debug </outputpath >
< enableupdateable > True </enableupdateable >
< Usemerge > True </usemerge >
< Singleassemblyname > Startkit_deploy </singleassemblyname >
</PropertyGroup >
< PropertyGroup Condition = "' $ (Configuration) |$ (Platform) ' = = ' release| AnyCPU ' ">
< DebugSymbols > False </debugsymbols >
< OutputPath >/release </outputpath >
Notoginseng < enableupdateable > True </enableupdateable >
< Usemerge > True </usemerge >
< Singleassemblyname > Startkit_deploy </singleassemblyname >
</PropertyGroup >
< ItemGroup >
</ItemGroup >
The ItemGroup node below <!--is optional, which is the same as in the project file Startkit.csproj-->
< ItemGroup >
< projectreference Include = ". /bll/bll.csproj ">
< Project > {73a293a1-cdcc-4919-9b05-ba2531addb56} </Project >
< name > BLL </name >
</projectreference >
< projectreference Include = ". /dal/dal.csproj ">
< Project > {aff6077d-dd2d-48a0-bfad-051bd67a6953} </Project >
Wuyi < Name > DAL </name >
</projectreference >
< projectreference Include = ". /ibll/ibll.csproj ">
< Project > {620770bb-7a27-4585-9b97-44eee349121d} </Project >
< name > IBLL </name >
</projectreference >
< projectreference Include = ". /model/model.csproj ">
< Project > {ea43ec2e-5890-4431-bd3e-5f6c090dea3a} </Project >
< name > Model </name >
</projectreference >
</ItemGroup >
<!--introduced Msbuildcommunitytasks-->
< Import Project = "$ (msbuildextensionspath)/msbuildcommunitytasks/msbuild.community.tasks.targets"/>
< send--> Mail!--
<target <!--name= "Emailtest" >
<message Text = "Mail sending" ></Message>
<mail smtpserver= "$ (smtpservername)"
subject= "Test"
Password= "$ (MailPassword)"
From = "$ (fromaddress)"
to = "$ (toaddress)"
Body= ' This is a test of the ' Mail task. '/>
</Target>-->
<!--backup files to FTP-->
<!--<target name= "Backup" dependsontargets= "Zip" >
<ftpupload username= "$ (ftpname)"
Password= "$ (FTPPassword)"
Localfile= "$ (zipfilename)"
Remoteuri= "ftp://192.168.1.2/sourcebackup/$ (zipfilename)"/>
<onerror executetargets= "Handleerrorbackup"/>
Bayi </Target>-->
When <!--backup files to ftp failed send mail-->
<!--<target name= "Handleerrorbackup" >
<message text= "Backup failed"/>
<mail smtpserver= "$ (smtpservername)"
To= "$ (toaddress)"
From= "$ (fromaddress)"
Subject= "$ (ProjectName) build Failed"
body= "Backup failure:could not finish backup."/>
</Target>-->
--> <!--compilation project
< Target Name = "Buildprojectreferences" >
< MSBuild Projects = "@ (projectreference)" Targets = "Build"/>
</Target >
<!--generate compressed Files-->
< Target Name = "Zip" >
<!--time format-->
< time Format = "YYYYMMDDHHMMSS" >
< Output TaskParameter = "Formattedtime" propertyname = "Builddate"/>
</time >
< zip Files = "@ (zipfiles)" Zipfilename = "Startkit v$ (Major)-$ (Minor)-$ (Revision)-$ (builddate). Zip"/>
102 </Target >
<!--copy files-->
< Target Name = "Copy" >
<!--stop IIS services-->
< ServiceController ServiceName = "w3svc" Action = "Stop"/>
<!--copy compiled files to a specified location using Robocopy/xd is the folder to ignore,/xf the file type to ignore-->
108 < Exec Command = "Robocopy Debug c:/inetpub/startkit/mir/xd Fckeditor attachments. svn obj. doc test/xf *.zip *. Wdproj *.user *.cs *.csproj "Ignoreexitcode =" true "/>
109 <!--start the IIS service-->
< ServiceController ServiceName = "w3svc" Action = "Start"/>
</Target >
112 <!--introduced webdeployment-->
113 < Import Project = "$ (msbuildextensionspath)/microsoft/webdeployment/v9.0/microsoft.webdeployment.targets"/ >
114 <!--to modify your build process, add your task inside one of the targets below and uncomment it.
Similar extension points exist, Microsoft.WebDeployment.targets. -->
116 < Target Name = "BeforeBuild" ></target >
117 < Target Name = "Beforemerge" ></target >
118 < Target Name = "Aftermerge" ></target >
119 < Target Name = "Afterbuild" >
<!--after successful compilation, perform the following targets-->
121 <! -Do not want to generate ZIP file, you can note the following zip target-->
122 < CallTarget Targets = "Zip"/>
123 < CallTarget Targets = "Copy"/>
124 <!--<calltarget targets= "Emailtest"/>
<calltarget targets= "Backup"/>-->
126 </Target >
127 </Project >

When you have successfully compiled your deployment project, open the C:/inetpub/startkit folder to see if you have successfully replicated the past. OK, I'll go and see, haha, the file is all right, OK, success.

At this point, create a virtual directory or Web site on IIS that points to the directory specified in our deployment project. We have added the project to the CCNet, so after each time we submit the code, MSBuild compiles the entire solution "of course the deployment project", and if the compilation succeeds, it automatically deploys the latest program to our site. This will enable the site and our development real-time synchronization, this is not the only way to implement, there are many other ways to achieve this function, you can discuss and communicate here.

Add:
Microsoft Build Engine (MSBuild) is a new generation platform for Microsoft and Visual Studio. MSBuild is completely transparent about how to process and build software, enabling developers to organize and build products in a build lab environment that does not have Visual Studio installed. With these tutorials, we can see that MSBuild is powerful and if you want to understand more about MSBuild, check out here http://msdn.microsoft.com/zh-cn/library/ms171451.aspx.

If you're unfamiliar with what I'm explaining, it's a good idea to look at this series of tutorials from the beginning: a series of tutorials on project management practice.

Related Article

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.