zoukankan      html  css  js  c++  java
  • Jenkins搭建.NET自动编译测试与发布环境

    本文地址: 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:WindowsMicrosoft.NETFramework64v4.0.30319MSbuild.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错误. 例如

    [plain] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. error MSB4019: The imported project "C:Program Files (x86)MSBuildMicrosoftVisualStudiov11.0WebApplicationsMicrosoft.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)出现了, 如0s+(Errors)

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


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

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

    使用如下参数

    [plain] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. /t:ResolveReferences;Compile /t:_CopyWebApplication /p:Configuration=Release /p:WebProjectOutputDir=C:Jenkins_Publish /p:OutputPath=C:Jenkins_Publishin  

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

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

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

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

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

    [html] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. <?xml version="1.0" encoding="utf-8"?>  
    2.   
    3. <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
    4.   <PropertyGroup>  
    5.     <WebPublishMethod>FileSystem</WebPublishMethod>  
    6.     <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>  
    7.     <LastUsedPlatform>Any CPU</LastUsedPlatform>  
    8.     <SiteUrlToLaunchAfterPublish />  
    9.     <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>  
    10.     <ExcludeApp_Data>False</ExcludeApp_Data>  
    11.     <publishUrl>C:Jenkins_PublishDEV_Metadata</publishUrl>  
    12.     <DeleteExistingFiles>True</DeleteExistingFiles>  
    13.   </PropertyGroup>  
    14. </Project>  

    可以直接在此修改配置。最后提交到源代码管理中

    最后配置参数即可

    [plain] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. /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

  • 相关阅读:
    Selenium库的使用
    Win10 常用快捷键
    503.下一个更大元素 II
    456.132模式
    201.数字范围按位与
    78.子集
    299.猜数字游戏
    49.字母异位词分组
    36.有效的数独
    290.单词规律
  • 原文地址:https://www.cnblogs.com/soundcode/p/6612796.html
Copyright © 2011-2022 走看看