用户可以根据本地文件或者SVN目录中的最新资料来进行本地编译后将Release文件自动拷贝,Web目录自动拷贝后压缩,生成Zip文件来部署。这个方法的优点是操作简单,容易和其他工具并用。
Build.bat 内容:
@ECHO OFF
SET / P DeployConfig = Specify build target ( 'Production' or 'Development' ) :
IF / I NOT '%DeployConfig%' == 'Production' (
IF / I NOT '%DeployConfig%' == 'Development' (
ECHO Please specify Production or Development .
GOTO finish
)
)
SET / P VersionTag = Enter SVN revision ( e . g . 1.2 . 4 ), or 'trunk':
echo .
msbuild project . msbuild / p :VersionTag = %VersionTag% ; DeployConfig = %DeployConfig% / nologo
rem IF %ERRORLEVEL% GTR 0 (
rem ECHO.
rem ECHO Build failed for revision number '%VersionTag%'
rem ECHO.
rem ) ELSE (
rem
rem echo Build succeeded for revision number '%VersionTag%'
rem )
:finish
project.msbuild内容:
< Project xmlns ="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets ="DeploymentZip" >
< PropertyGroup >
< DefaultConfiguration > Release </ DefaultConfiguration >
< DefaultSvnServer > 192.168.0.2 </ DefaultSvnServer >
</ PropertyGroup >
<!-- Choose>
<When Condition="'$(VersionTag)' == 'trunk'">
<PropertyGroup>
<RepositoryPath>svn://$(DefaultSvnServer)/MYProject/trunk</RepositoryPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<RepositoryPath>svn://$(DefaultSvnServer)/MYProject/tags/$(VersionTag)</RepositoryPath>
</PropertyGroup>
</Otherwise>
</Choose -->
<!-- Retrieve project files from source control, of the specified revision -->
<!-- Target Name="SvnExport">
<RemoveDir Directories="buildExport" />
<MakeDir Directories="buildExport" />
<SvnExport
RepositoryPath="$(RepositoryPath)/web"
LocalPath="buildExport/Web"
Username="deploy"
Password="readonly" />
<SvnExport
RepositoryPath="$(RepositoryPath)/api"
LocalPath="buildExportAPI"
Username="deploy"
Password="readonly" />
</Target -->
< ItemGroup >
< WebFiles Include ="..Web***.*" Exclude ="..Web**.svn**;..Web***.pdb" />
</ ItemGroup >
<!-- Compile API -->
<!-- Target Name="API" DependsOnTargets="SvnExport" -->
< Target Name ="CompileAPI" >
< MSBuild
Projects ="..APIapi.csproj"
StopOnFirstFailure ="true"
Properties ="Configuration=$(DefaultConfiguration)" />
</ Target >
< Target Name ="CopyEverything" DependsOnTargets ="CompileAPI" >
< RemoveDir Directories ="buildExport" />
< MakeDir Directories ="buildExport" />
< MakeDir Directories ="buildExportWeb" />
< MakeDir Directories ="buildExportAPI" />
< Copy
SourceFiles ="..APIin$(DefaultConfiguration)MYProject.dll"
DestinationFolder ="buildExportWebin" />
< Copy
SourceFiles ="@(WebFiles)"
DestinationFiles ="@(WebFiles->'buildExportWeb%(RecursiveDir)%(Filename)%(Extension)')" />
</ Target >
< Target Name ="CopyWebConfig" DependsOnTargets ="CopyEverything" >
< Copy
SourceFiles ="buildExportWebConfig$(DeployConfig)Web.config"
DestinationFiles ="buildExportWebWeb.config" />
< RemoveDir Directories ="buildExportWebConfig" />
</ Target >
<!-- Zip up all the files for transporting to deploy -->
< Target
Name ="DeploymentZip"
DependsOnTargets ="CopyEverything;CopyWebConfig"
Condition ="('$(DeployConfig)' == 'QA' OR '$(DeployConfig)' == 'Production' OR '$(DeployConfig)' == 'Development') AND '$(VersionTag)' != ''"
>
< CreateItem
Include ="buildExportWeb**;" >
< Output TaskParameter ="Include" ItemName ="WebAppFiles" />
</ CreateItem >
< Zip
Files ="@(WebAppFiles)"
ZipFileName ="MYProject_$(DeployConfig)_$(VersionTag).zip"
WorkingDirectory ="buildExportWeb" />
< Message Text ="Built deployment file with $(DefaultConfiguration) for $(DeployConfig)." />
< Message Text ="Deployment package: MYPROJECT_$(DeployConfig)_$(VersionTag).zip" />
< Message Text ="Done." />
</ Target >
< UsingTask TaskName ="MSBuild.Community.Tasks.Subversion.SvnExport" AssemblyFile ="$(MSBuildExtensionsPath)MSBuildCommunityTasksMSBuild.Community.Tasks.dll" />
< UsingTask TaskName ="MSBuild.Community.Tasks.Zip" AssemblyFile ="$(MSBuildExtensionsPath)MSBuildCommunityTasksMSBuild.Community.Tasks.dll" />
</ Project >
这2个文件没有进行优化,根据不同项目有很大改动余地。但基本功能都经过测试。在XML模式下编辑可以方便看到很多地方我都注释了,也都通过测试。相信对大多用户有所帮助。