问题描述
我希望开始使用MS-Build.到目前为止,我有很多项目是从Visual Studio手动构建的.我想自动化构建过程,最好是从不想安装Visual Studio的机器上自动化.我开始阅读有关MSDN上的MS-Build的信息.但是我还没有逐步的指导,从何处开始以及如何做.我的问题是:
I wish to start using MS-Build. I have lots of projects which I build manually (from Visual Studio) as of now. I want to automate build process and preferably from a machine onto which I don't wish to install Visual Studio. I started reading about MS-Build on MSDN. But I am yet to get a step by step guidance where to start and how to do. My questions are like:
- 如何启动MS-Build?是否有任何可下载的内容?
- 第一步是什么?
- 如何创建MS-Build脚本?
还有很多类似的问题.有人可以引导我吗?
And a lot similar questions. Can somebody guide me?
推荐答案
MS Build随附.NET Framework本身,并且可执行文件(msbuild.exe)位于.NET-framework目录中,类似于(取决于版本) ):
MS Build comes with the .NET Framework itself and the executable (msbuild.exe) is located in the .NET-framework directory, something like (depending on version):
- C:\ WINDOWS \ Microsoft.NET \ Framework \ v4.0.30319
- C:\ WINDOWS \ Microsoft.NET \ Framework \ v3.5
- C:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727
(从开始菜单使用"Visual Studio命令提示符"时,正确的版本也位于%path%中.)
(The right version is also in %path% when using the "Visual Studio command prompt" from the start menu.)
MsBuild文件是xml文件.您可以先制作一个新的文本文件,例如说"c:\ myscript.msbuild",然后将其复制粘贴到文件中:
MsBuild files are xml-files. You can start by making a new text file, lets say "c:\myscript.msbuild", and copy-paste this to the file:
<Project DefaultTargets="MyTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="MyTarget">
<Message Text="Hello world!" Importance="high"/>
</Target>
</Project>
然后转到命令提示符并键入:
Then go to command prompt and type:
C:\ WINDOWS \ Microsoft.NET \ Framework \ v4.0.30319 \ msbuild.exe c:\ myscript.msbuild
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe c:\myscript.msbuild
这是一个好的开始. :)
That is a good start. :)
然后,您可以自定义目标和属性.第二个例子:
Then you can customize the targets and properties.Second example:
<Project DefaultTargets="All" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(MyCondition)' == 'x'" >
<MyProperty>World2</MyProperty>
</PropertyGroup>
<Target Name="MyTarget">
<Message Text="Hello" Importance="high"/>
<Message Text="$(MyProperty)" Importance="high"/>
</Target>
<Target Name="MyTarget2">
</Target>
<Target Name="All">
<CallTarget Targets="MyTarget" />
<CallTarget Targets="MyTarget2" />
</Target>
</Project>
C:\ WINDOWS \ Microsoft.NET \ Framework \ v4.0.30319 \ msbuild.exe c:\ myscript.msbuild/target:mytarget/property:MyCondition = x
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe c:\myscript.msbuild /target:mytarget /property:MyCondition=x
您还可以在构建文件中包含构建文件.
You can have also build files inside build-files.
<Project DefaultTargets="MyTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="MyExternalProperties.msbuild"/>
<Target Name="MyTarget">
<Exec Command="echo Hello world 3"/>
</Target>
</Project>
这篇关于如何在MS-Build上启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!