SlideShare une entreprise Scribd logo
1  sur  15
MsBuild的初體驗
2013.08.30
Bryan Lin
Agenda
• Why MsBuild?
• 認識MsBuild
• 範例實作
Why MsBuild?
• 當我們要發佈站台的時候:
• 取得最新版本
• 所有程式都要Build過

• 更改設定
• …(其他步驟)
• 產出檔案要publish至對應的目錄
Why MsBuild?
• 有這麼多步驟要做,而且要分別執行,很麻煩。
• 有沒有一個方法只執行一次就做完所有動作?
• 就是MsBuild了!
認識MsBuild
• MsBuild是什麼?能做到那些事情?
• 是一個Xml格式的文件
• 裡面描述了專案所包含的檔案有哪些,建置的設定等等資訊(ex. *.csproj檔案)

• 也可以使用MsBuild來撰寫建置站台所需要的流程
認識MsBuild
• MsBuild的基本框架
• MsBuild的內容其實是由一個Project包含著多個Target所組合而成,
再依照參數的不同來決定將會執行那些Target

• 範例如下:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/deve
loper/msbuild/2003">
<Target Name="Build">
<Message Text="Hello Msbuild!" />

</Target>
</Project>
認識MsBuild
• 在專案檔中我們指定了預設執行的Target為Build,
在Build之中執行了顯示訊息的任務

• 執行方式:在Visiual Stuiod Cmd中,執行MsBuild <你的Build檔案>
• 在畫面上輸出Hello Msbuild!
認識MsBuild
• 想執行多個任務,範例如下:
認識MsBuild
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<CallTarget Targets="Step 1"/>
<CallTarget Targets="Step 2"/>
</Target>
<Target Name="Step 1">
<Message Text="Step 1" />
</Target>
<Target Name="Step 2">
<Message Text="Step 2" />
</Target>

</Project>
認識MsBuild
• 想要了解更多有關MsBuild的資訊?
• 請洽http://msdn.microsoft.com/zh-tw/library/dd393574.aspx
範例實作
• 取得目前專案的ChangeSet,並將此ChangeSet寫入AssemblyVersion
範例實作
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectSourceControl>./</ProjectSourceControl>

<VersionTextPath>version.txt</VersionTextPath>
<MajorVersion Condition="$(MajorVersion) == ''">8</MajorVersion>
<MinorVersion Condition="$(MinorVersion) == ''">1</MinorVersion>
<ProgramFiles32 Condition="$(ProgramW6432) != ''">C:Program Files (x86)</ProgramFiles32>
<ProgramFiles32 Condition="$(ProgramFiles32) == ''">C:Program Files</ProgramFiles32>
<VS10Dir>$(ProgramFiles32)Microsoft Visual Studio 10.0</VS10Dir>
<VS11Dir>$(ProgramFiles32)Microsoft Visual Studio 11.0</VS11Dir>
<TF Condition="Exists('$(VS10Dir)')">&quot;$(VS10Dir)Common7IDETF.exe&quot;</TF>
<TF Condition="Exists('$(VS11Dir)')">&quot;$(VS11Dir)Common7IDETF.exe&quot;</TF>
</PropertyGroup>
範例實作(續)
<Target Name="GetVersion" BeforeTargets="Build" Condition="$(Configuration.Contains('Release'))">
<Message Text="***************** $(Configuration)" Importance="high" />
<Exec Command="$(TF) history /stopafter:1 /noprompt /recursive $(ProjectSourceControl) > $(VersionTextPath)"/>
<PropertyGroup>
<VersionContent>$([System.IO.File]::ReadAllText('$(VersionTextPath)'))</VersionContent>
<CurrentVersion>$([System.Text.RegularExpressions.Regex]::Match($(VersionContent), '*?s*(?&lt;version&gt;d+)s*(S*)?s*((?&lt;year&gt;d{4})/(?&lt;month&gt;d{0,2})/(?&lt;day&gt;d{0,2})).*?$').Groups["version"].Value)</CurrentVersion>
<CurrentVersionYear>$([System.Text.RegularExpressions.Regex]::Match($(VersionContent), '*?s*(?&lt;version&gt;d+)s*(S*)?s*((?&lt;year&gt;d{4})/(?&lt;month&gt;d{0,2})/(?&lt;day&gt;d{0,2})).*?$').Groups["year"].Value)</CurrentVersionYear>
<CurrentVersionMonth>$([System.Text.RegularExpressions.Regex]::Match($(VersionContent), '*?s*(?&lt;version&gt;d+)s*(S*)?s*((?&lt;year&gt;d{4})/(?&lt;month&gt;d{0,2})/(?&lt;day&gt;d{0,2})).*?$').Groups["month"].Value)</CurrentVersionMonth>
<CurrentVersionDay>$([System.Text.RegularExpressions.Regex]::Match($(VersionContent), '*?s*(?&lt;version&gt;d+)s*(S*)?s*((?&lt;year&gt;d{4})/(?&lt;month&gt;d{0,2})/(?&lt;day&gt;d{0,2})).*?$').Groups["day"].Value)</CurrentVersionDay>

<CurrentDate>$([System.DateTime]::Today.ToString("MMdd"))</CurrentDate>
<AssemblyVersion>$(MajorVersion).$(MinorVersion).$(CurrentVersion).$(CurrentVersionMonth)$(CurrentVersionDay)</AssemblyVersion>
</PropertyGroup>
範例實作(續)
<Delete Files="$(VersionTextPath)" />
<Message Text="***************** $(AssemblyVersion)" Importance="high" />
<Exec Command="ATTRIB -R $(ProjectDir)PropertiesVersionInfo.cs" />

<WriteLinesToFile
Condition=" '$(AssemblyVersion)' != '' " File="$(ProjectDir)PropertiesVersionInfo.cs"
Overwrite="True"
Lines="[assembly: System.Reflection.AssemblyVersion(&quot;$(AssemblyVersion)&quot;)]
[assembly: System.Reflection.AssemblyFileVersion(&quot;$(AssemblyVersion)&quot;)]" />
</Target>
</Project>
參考資料
http://msdn.microsoft.com/zh-tw/library/dd393574.aspx
http://ithelp.ithome.com.tw/question/10107277?tag=ithome.nq

Contenu connexe

En vedette

20131104 basic msbuild by Anney
20131104 basic msbuild by Anney20131104 basic msbuild by Anney
20131104 basic msbuild by AnneyLearningTech
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous Deploymentwlscaudill
 
MSDN Live - CI using TFS11 & NuGet
MSDN Live - CI using TFS11 & NuGetMSDN Live - CI using TFS11 & NuGet
MSDN Live - CI using TFS11 & NuGetXavier Decoster
 
2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGETDaniel Fisher
 
An overview of the NuGet ecosystem - Mobel.io
An overview of the NuGet ecosystem - Mobel.ioAn overview of the NuGet ecosystem - Mobel.io
An overview of the NuGet ecosystem - Mobel.ioMaarten Balliauw
 

En vedette (7)

Nu get advanced
Nu get advancedNu get advanced
Nu get advanced
 
20131104 basic msbuild by Anney
20131104 basic msbuild by Anney20131104 basic msbuild by Anney
20131104 basic msbuild by Anney
 
Nuget
NugetNuget
Nuget
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous Deployment
 
MSDN Live - CI using TFS11 & NuGet
MSDN Live - CI using TFS11 & NuGetMSDN Live - CI using TFS11 & NuGet
MSDN Live - CI using TFS11 & NuGet
 
2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET2011 - Dotnet Information Day: NUGET
2011 - Dotnet Information Day: NUGET
 
An overview of the NuGet ecosystem - Mobel.io
An overview of the NuGet ecosystem - Mobel.ioAn overview of the NuGet ecosystem - Mobel.io
An overview of the NuGet ecosystem - Mobel.io
 

Similaire à Ms build的初體驗

DevOps的神鬼奇航
DevOps的神鬼奇航DevOps的神鬼奇航
DevOps的神鬼奇航Edward Kuo
 
我們與Azure DevOps的距離
我們與Azure DevOps的距離我們與Azure DevOps的距離
我們與Azure DevOps的距離Edward Kuo
 
李成银:前端编译平台
李成银:前端编译平台李成银:前端编译平台
李成银:前端编译平台taobao.com
 
Java Build Tool course in 2011
Java Build Tool course in 2011Java Build Tool course in 2011
Java Build Tool course in 2011Ching Yi Chan
 
Git&Github Tutorial
Git&Github TutorialGit&Github Tutorial
Git&Github TutorialTing Wen Su
 
Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Chu-Siang Lai
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922Earou Huang
 
前端也能變全端
前端也能變全端前端也能變全端
前端也能變全端ericpi Bi
 
02.uliweb开发入门
02.uliweb开发入门02.uliweb开发入门
02.uliweb开发入门modou li
 
Open source的devops工具箱 公開版@coscup2016
Open source的devops工具箱 公開版@coscup2016Open source的devops工具箱 公開版@coscup2016
Open source的devops工具箱 公開版@coscup2016Kirk Chen
 
開發工具與環境建置
開發工具與環境建置開發工具與環境建置
開發工具與環境建置Shengyou Fan
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛Edward Kuo
 
Intro to Git 投影片
Intro to Git 投影片Intro to Git 投影片
Intro to Git 投影片Tony Yeh
 
30 分鐘安裝 Drupal 企業網站
30 分鐘安裝 Drupal 企業網站30 分鐘安裝 Drupal 企業網站
30 分鐘安裝 Drupal 企業網站tripocom
 
面向未来的前端类库开发 — KISSY 类库构想与实践
面向未来的前端类库开发  — KISSY 类库构想与实践面向未来的前端类库开发  — KISSY 类库构想与实践
面向未来的前端类库开发 — KISSY 类库构想与实践taobao.com
 
KISSY Mechanism
KISSY MechanismKISSY Mechanism
KISSY Mechanismlifesinger
 
[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇
[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇
[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇Shengyou Fan
 
基于Seajs的项目构建
基于Seajs的项目构建基于Seajs的项目构建
基于Seajs的项目构建Zhang Xiaoxue
 
杨皓 新浪博客前端架构分享
杨皓 新浪博客前端架构分享杨皓 新浪博客前端架构分享
杨皓 新浪博客前端架构分享isnull
 
從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用謝 宗穎
 

Similaire à Ms build的初體驗 (20)

DevOps的神鬼奇航
DevOps的神鬼奇航DevOps的神鬼奇航
DevOps的神鬼奇航
 
我們與Azure DevOps的距離
我們與Azure DevOps的距離我們與Azure DevOps的距離
我們與Azure DevOps的距離
 
李成银:前端编译平台
李成银:前端编译平台李成银:前端编译平台
李成银:前端编译平台
 
Java Build Tool course in 2011
Java Build Tool course in 2011Java Build Tool course in 2011
Java Build Tool course in 2011
 
Git&Github Tutorial
Git&Github TutorialGit&Github Tutorial
Git&Github Tutorial
 
Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922
 
前端也能變全端
前端也能變全端前端也能變全端
前端也能變全端
 
02.uliweb开发入门
02.uliweb开发入门02.uliweb开发入门
02.uliweb开发入门
 
Open source的devops工具箱 公開版@coscup2016
Open source的devops工具箱 公開版@coscup2016Open source的devops工具箱 公開版@coscup2016
Open source的devops工具箱 公開版@coscup2016
 
開發工具與環境建置
開發工具與環境建置開發工具與環境建置
開發工具與環境建置
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
 
Intro to Git 投影片
Intro to Git 投影片Intro to Git 投影片
Intro to Git 投影片
 
30 分鐘安裝 Drupal 企業網站
30 分鐘安裝 Drupal 企業網站30 分鐘安裝 Drupal 企業網站
30 分鐘安裝 Drupal 企業網站
 
面向未来的前端类库开发 — KISSY 类库构想与实践
面向未来的前端类库开发  — KISSY 类库构想与实践面向未来的前端类库开发  — KISSY 类库构想与实践
面向未来的前端类库开发 — KISSY 类库构想与实践
 
KISSY Mechanism
KISSY MechanismKISSY Mechanism
KISSY Mechanism
 
[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇
[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇
[JCConf 2022] Compose for Desktop - 開發桌面軟體的新選擇
 
基于Seajs的项目构建
基于Seajs的项目构建基于Seajs的项目构建
基于Seajs的项目构建
 
杨皓 新浪博客前端架构分享
杨皓 新浪博客前端架构分享杨皓 新浪博客前端架构分享
杨皓 新浪博客前端架构分享
 
從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用
 

Plus de LearningTech

Plus de LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Ms build的初體驗