Publish an msbuild Task component-used to publish multiple websites at the same time

Source: Internet
Author: User

Component Project:/files/jillzhang/publishers.rar

Demo project:/files/jillzhang/publisersample.rar 

When VS 2005 does not support sp1, you can use aspnet_compiler.exe to publish a website. It is a command line tool that facilitates continuous integration. You can publish a website even after SP1 is used.

But I searched through the vs installation component and did not find the EXE used for website publishing. Without the command line tool, continuous integration became a problem, the following describes the functions and features of the component.

1. original use of this component

In the continuous integration process, when msbuild.exe is compiled successfully, the website is automatically published using this component. Support multiple websites at a time

2. Implementation Principle

The best way to interact with msbuild is to use this component as a task of msbuild ,. NET framework has been prepared for us to create a base class Microsoft msbuild. build. utilities. task, which can be inherited to implement a custom msbuild task and perform the desired operations during compilation. Based on the configuration information, I copied the files in the specified format from the compiled website folder to the publishing directory to publish the website. Any website project developed in VB. NET and C # or other languages can be used as long as the configuration is changed.

3. Implementation Method

First, let's take a look at the usage of the Microsoft. Build. Utilities. Task class:

To implement a custom msbuild task, you must overwrite the execute method in the implementation class of Microsoft. Build. Utilities. task. The prototype of this method is

Public Abstract

  Execute()
 

In addition, msbuild tasks support Custom Attributes. The implementation method is the same as that of common class attributes. If the attributes are required, you can apply the [required] attribute ).

The attributes required by this component are as follows:

Attribute name

Data Type

Required?

Remarks

Sourcedir

String

Yes

Website directory. You can specify the directory names of multiple websites, which are separated by commas (,).

Targetdir

String

Yes

Release directory. You can specify the release directories for multiple websites. The number of directories must be the same as that in sourcedir. Each directory is separated by a comma, and the order corresponds to the configuration of sourcedir.

Excluedstr

String

No

It indicates the suffix of a file that is not copied at the time of release. It can contain multiple suffixes separated by commas (,).

Declare these attributesCodeIs:

Copy files in the execute method, which can be found in the component project.

This component can record the execution result and execution process through log.

4. Usage

To demonstrate the effect of this component, we create a solution named publisersample. sln. The solution includes two websites, sample1 and sample2. The structure is shown in:

Our purpose is to publish the two websites to the sample‑publiserdir and smaple2_publiserdir directories at the same time of compilation.

Here, we only demonstrate how to use this component in the msbuild.exe command line. The steps are as follows:

    1. Copy the publishers. dll file of this component and the fileuntility. dll file on which it depends to the same directory as. sln.
    2. Create a publisersample. msbuild file in the same directory of. sln. Add the following generation in publisersample. msbuild according to the project path on my machine
        
    3. Create a. BAT file named execution demo. bat. Enter the following code: 

    1. Execute the demo. bat.

    1. View sample1_publiserdir and smaple2_publiserdir and find that the website has been published successfully.

 

5. project files and demo projects

Component Project:/files/jillzhang/publishers.rar

Demo project:/files/jillzhang/publisersample.rar

 

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.