本文地址: http://blog.csdn.net/wangjia184/article/details/18365553


操作系统Windows, 确保需要的.NET Framework已经安装

从 http://jenkins-ci.org/下载Windows安装包。

安装后,访问http://localhost:8080 . 

Jenkins => Manager Jenkins => Manage Plugins



Available选项卡中,选中MSBuild Plugin 


然后点击安装


安装完后, 切换到 Jenkins => Manager Jenkins => Configure System


找到MSBuild那节,填入 MSBuild的路径


C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSbuild.exe


然后点击 New Job, 输入任务名称


然后配置好源代码管理,例如SVN


然后到Build节,


MSBuilder Version 为之前配置的 "Version 4.0"

MSBuild Build File 是项目文件或者工程文件的名称

然后就是MSBuild的命令行参数了。

/t:Rebuild 表示每次都重建,不使用增量编译

/property:Configuration=Release 表示编译Release版本,

/property:TargetFrameworkVersion=v4.5表示编译的目标是.NET 4.5

保存后,点击左侧Build Now开始测试一次编译。


如果编译过程中出现错误,需查看Console Output.

一种常见的错误情况是:编译的机器上没有安装Visual Studio, 在编译的过程中可能会引发MSB4019错误. 例如

error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

对于这种情况,可以将开发机上的C:\Program Files (x86)\MSBuild文件夹之间拷贝到编译机上。

如果成功,则显示 0 Error(s),在编译成功后可以启动单元测试,如果有NUnit的话. 

部署的话,可以通过批处理完成, 首先安装 Post build task插件, 与之前MSBuild插件的安装方式一样


然后在Job的配置中,添加post build task



在Log Text那,可以使用正则表达式检测0 Error(s)出现了, 如\b0\s+(Error\(s\))

Script中直接调用磁盘上的批处理文件


补充1.如何发布VS2010的Web站点 

如果是发布Web站点,可以直接指定需要发布站点的csproj文件,如


使用如下参数

/t:ResolveReferences;Compile /t:_CopyWebApplication /p:Configuration=Release /p:WebProjectOutputDir=C:\Jenkins_Publish /p:OutputPath=C:\Jenkins_Publish\bin

其中WebProjectOutputDir是web站点的发布路径;OutputPath是编译输出的dll路径


补充2.如何发布VS2012的Web站点 

首先在VS2012中新建发布配置项


配置好发布方式,比如以“文件系统”方式发布,需要注意的是,目标位置是编译服务器上的路径



在保存后,在项目的Properties/PublishProfiles可以找到这些*.pubxml文件

<?xml version="1.0" encoding="utf-8"?>

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>C:\Jenkins_Publish\DEV_Metadata</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>
可以直接在此修改配置。最后提交到源代码管理中

最后配置参数即可


/t:Rebuild /p:Configuration=Release;PublishProfile=Jenkins-DEV;DeployOnBuild=true;VisualStudioVersion=11.0

PublishProfile指定创建的Profile名称(没有扩展名)

DeployOnBuild=true 表示启用编译并发布

VisualStudioVersion=11.0 表示VS2012



本文地址: http://blog.csdn.net/wangjia184/article/details/18365553




Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐