Building Apps with MSBuild

Source: Internet
Author: User

MSBuild is a platform that Microsoft provides to build applications that you can use to control and process your software engineering through an XML configuration file. It's also integrated into VS, and it doesn't depend on vs.

The constituent elements of an XML configuration (Schema):

    • Project files

Property

Item

Task

Goal

Property:
< PropertyGroup >    < AssemblyName > MSBuildSample</AssemblyName>    <OutputPath  >bin\</OutputPath>  </PropertyGroup  >
Item
< ItemGroup >    <  Include= "HelloWorld.cs"/>  </ItemGroup  >
Task:
    <directories= "$ (OutputPath)"  Condition= "! Exists (' $ (OutputPath) ') "/>    <Sources=" @ (Compile) "  outputassembly= "$ (OutputPath) $ (AssemblyName). exe"/>
Goal: The goal is to combine some tasks in order
<target name= "Build" Span style= "color: #0000ff;" >> <makedir = "$ (OutputPath)"  Condition="! Exists (' $ (OutputPath) ') "/> <CSC sources= "@ (Compile)"  Outputassembly=" $ (OutputPath) $ (AssemblyName). exe " Span style= "color: #0000ff;" >/> </target                

Here is one of the simplest XML Schema files on MSDN:

<Projectxmlns= "http://schemas.microsoft.com/developer/msbuild/2003">  <ItemGroup>    <CompileInclude= "HelloWorld.cs" />  </ItemGroup>  <TargetName= "Build">    <CSCSources= "@ (Compile)"/>    </Target></Project>

The file compiles the HelloWorld.cs file through a task.

The following is a simple example of building a C/S architecture application:

XML file-defined properties:
<PropertyGroup>    <OutDir>Output</OutDir>    <Outserverdir>$ (OutDir) server</Outserverdir>    <Outclientdir>$ (OutDir) client</Outclientdir>    <Solutionfile>.. \xx\ your project document. sln</Solutionfile>    <Serverdir>xx\xx\ Project compiled Bin\server directory</Serverdir>    <Clientdir>xx\xx\ Project compiled bin\client directory</Clientdir></PropertyGroup>

An XML file defines the item:
< ItemGroup >    <  Include= "$ (serverdir) \**\*.*"  Exclude= "File definition you want to exclude"/>    <Include= "$ (clientdir) \**\*.*"  Exclude= " You want to exclude the file definition "/></ItemGroup>

A list of tasks defined by the XML file:
    1. Clean
    2. Init
    3. Build
    4. Relesase
<TargetName= "clean">        <RemoveDirDirectories= "$ (OutDir)"/>    </Target>        <TargetName= "Init"DependsOnTargets= "clean">        <MakeDirDirectories= "$ (OutDir)"/>        <MakeDirDirectories= "$ (outserverdir)"/>        <MakeDirDirectories= "$ (outclientdir)"/>    </Target>        <TargetName= "Build"DependsOnTargets= "Init">        <MSBuildProjects= "$ (solutionfile)"Targets= "Rebuild"Properties= "Configuration=release"/>    </Target>        <TargetName= "CopyFiles"DependsOnTargets= "Build">        <CopySourceFiles= "@ (serverdirfiles)"DestinationFiles= "@ (serverdirfiles-> ' $ (outserverdir) \% (recursivedir)% (Filename)% (Extension) ')"/>        <CopySourceFiles= "@ (clientdirfiles)"DestinationFiles= "@ (clientdirfiles-> ' $ (outclientdir) \% (recursivedir)% (Filename)% (Extension) ')"/>    </Target>
Summary of the above several fragments:
<ProjectDefaultTargets= "CopyFiles"xmlns= "http://schemas.microsoft.com/developer/msbuild/2003">    <PropertyGroup>        <OutDir>Output</OutDir>        <Outserverdir>$ (OutDir) server</Outserverdir>        <Outclientdir>$ (OutDir) client</Outclientdir>        <Solutionfile>.. \xx\ your project document. sln</Solutionfile>        <Serverdir>Xx\xx\ Project compiled Bin\server directory</Serverdir>        <Clientdir>Xx\xx\ Project compiled bin\client directory</Clientdir>    </PropertyGroup>    <ItemGroup>        <ServerdirfilesInclude= "$ (serverdir) \**\*.*"/>        <ClientdirfilesInclude= "$ (clientdir) \**\*.*"/>    </ItemGroup>        <TargetName= "clean">        <RemoveDirDirectories= "$ (OutDir)"/>    </Target>        <TargetName= "Init"DependsOnTargets= "clean">        <MakeDirDirectories= "$ (OutDir)"/>        <MakeDirDirectories= "$ (outserverdir)"/>        <MakeDirDirectories= "$ (outclientdir)"/>    </Target>        <TargetName= "Build"DependsOnTargets= "Init">        <MSBuildProjects= "$ (solutionfile)"Targets= "Rebuild"Properties= "Configuration=release"/>    </Target>        <TargetName= "CopyFiles"DependsOnTargets= "Build">        <CopySourceFiles= "@ (serverdirfiles)"DestinationFiles= "@ (serverdirfiles-> ' $ (outserverdir) \% (recursivedir)% (Filename)% (Extension) ')"/>        <CopySourceFiles= "@ (clientdirfiles)"DestinationFiles= "@ (clientdirfiles-> ' $ (outclientdir) \% (recursivedir)% (Filename)% (Extension) ')"/>    </Target></Project>
View Code

You can write a batch command when using this msbuild XML file:

@echo off %SystemRoot%\microsoft. NET\framework\v2.0.50727\msbuild build.xml/nologo/v: MPause


  

Building Apps with MSBuild

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.