自动发布web应用程序或者网站
来源:互联网 发布:网络fps游戏排行榜 编辑:程序博客网 时间:2024/06/11 15:21
由于需要自动化构建集成测试,所以需要一整套环境。
关键 1根据源代码的改动自动下载代码,2编译3发布网站
1第一步只需要通过CruiseControl.NET就可以做到
2编译其实就是在ccnet.config中添加一个任务,关键代码
- <tasks>
- <msbuild>
- <executable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Msbuild.exe</executable>
- <workingDirectory>$(baseDirectory)$(workingDirectory)$(projectName)\src\PollutantMonitorPlatform\PollutantMonitor</workingDirectory>
- <projectFile>$(baseDirectory)$(workingDirectory)$(projectName)\src\PollutantMonitorPlatform\PollutantMonitor\PollutantMonitor\PollutantMonitor.csproj</projectFile>
- <buildArgs>/noconsolelogger /p:OutDir=C:\SourceControl\publish\PollutantMonitor\ /v:n</buildArgs>
- <targets>Clean;Build;_CopyWebApplication</targets>
- <timeout>900</timeout>
- <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
- </msbuild>
- <exec>
- <executable>AddApp.bat</executable>
- <baseDirectory>C:\Program Files\CruiseControl.NET\server</baseDirectory>
- <buildArgs>PollutantMonitor 82 $(baseDirectory)TestWeb\PollutantMonitor "ASP.NET v4.0"</buildArgs>
- <buildTimeoutSeconds>10</buildTimeoutSeconds>
- </exec>
- </tasks>
- <publishers>
- <xmllogger/>
- <buildpublisher>
- <sourceDir>$(baseDirectory)$(publishDirectory)PollutantMonitor\_PublishedWebsites</sourceDir>
- <publishDir>C:\SourceControl\Test\</publishDir>
- <useLabelSubDirectory>false</useLabelSubDirectory>
- <alwaysPublish>false</alwaysPublish>
- </buildpublisher>
- </publishers>
通过应用msbuild.exe命令行就可以编译,不需要vs的开发环境。
网站项目的命令行如下:
- C:\Windows\Microsoft.NET\Framework\v3.5\Msbuild.exe F:\download\MSBuildDemo1\MSBuildDemo.sln
- /t:Clean;Build /p:OutDir=H:\testweb\
含义就是通过3.5版的Msbuild.exe编译路径F:\download\MSBuildDemo1下的solution文件MSBuildDemo.sln,首先清理,再生成,最后把生成的所有文件复制到目录下H:\testweb\
web应用程序项目的命令行如下:
- C:\Windows\Microsoft.NET\Framework\v3.5\Msbuild.exe
- F:\download\MSBuildDemo\BFL.MSBuildDemo.WebApp\BFL.MSBuildDemo.WebApp.csproj
- /t:Clean;Build;_CopyWebApplication /p:OutDir=H:\testweb\
含义就是通过3.5版的Msbuild.exe编译路径F:\download\MSBuildDemo\BFL.MSBuildDemo.WebApp\下的项目文件BFL.MSBuildDemo.WebApp.csproj ,首先清理,再生成,最后把生成的所有文件复制到目录下H:\testweb\
两种方式都在OutDir下生成了目录_PublishedWebsites,和通过vs右键发布生成的一样。
如何出现如下错误,需要修改csproj项目文件中的如下一行,需要改变版本,例如把v10.0改为v8.0或者v9.0
- <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
- C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(133,11): error MSB4064: The "Retries" parameter is not supported by the "Copy" task. Verify the parameter exists on the task, and it is a settable public instance property.
- C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(131,5): error MSB4063: The "Copy" task could not be initialized with its input parameters.
- Done Building Project "F:\download\MSBuildDemo\BFL.MSBuildDemo.WebApp\BFL.MSBuildDemo.WebApp.csproj" (Clean;Build;_CopyWebApplication target(s)) -- FAILED.
- Build FAILED.
- "F:\download\MSBuildDemo\BFL.MSBuildDemo.WebApp\BFL.MSBuildDemo.WebApp.csproj" (Clean;Build;_CopyWebApplication target) (1) ->
- (_CopyWebApplicationLegacy target) ->
- C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(133,11): error MSB4064: The "Retries" parameter is not supported by the "Copy" task. Verify the parameter exists on the task, and it is a settable public instance property.
- C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(131,5): error MSB4063: The "Copy" task could not be initialized with its input parameters.
- 0 Warning(s)
- 2 Error(s)
- Time Elapsed 00:00:00.42
由于上一步已经生成了发布需要的所有文件,所以这一步就是拷贝文件,设定虚拟目录,就可以了。我使用的是II7,IIS7有一个工具appcmd可以简化发布。
- %windir%\system32\inetsrv\appcmd add app /site.name:"Default Web Site" /path:/TestWeb
- /physicalPath:C:\SourceControl\Test\TestWeb\PollutantMonitor
含义调用appcmd在Default Web Site下添加一个web应用程序,虚拟路径为TestWeb,物理路径为C:\SourceControl\Test\TestWeb\PollutantMonitor
- %systemroot%\system32\inetsrv\APPCMD set app "Default Web Site/TestWeb" /applicationPool:"ASP.NET v4.0"
含义调用appcmd设置Default Web Site/TestWeb web应用程序的运行环境为ASP.NET v4.0
- %windir%\system32\inetsrv\appcmd delete app "Default Web Site/TestWeb"
通过一个bat文件自动添加应用程序和设置运行版本,文件内容如下:
重复添加会有错误,目前就是忽略,还没有找到好的方法
- if exist %windir%\system32\inetsrv\appcmd.exe (goto AddWeb) else (goto NOappcmd)
- :AddWeb
- echo 添加网站
- %windir%\system32\inetsrv\appcmd add site /name:%1 /bindings:http/*:%2: /physicalPath:%3
- if %errorlevel% equ 0 goto success
- if %errorlevel% gtr 0 goto failed
- :failed
- echo 获得错误返回码为%errorlevel%
- echo 添加网站failed
- goto end
- :success
- echo 添加网站successed
- echo 获得返回码为%errorlevel%
- echo 设置dotnet版本,启动网站
- %systemroot%\system32\inetsrv\APPCMD set app %1"/" /applicationPool:%4
- %systemroot%\system32\inetsrv\APPCMD start site %1
- goto end
- :NOappcmd
- echo %windir%\system32\inetsrv\appcmd.exe is not exist
- :end
需要注意的是以上命令需要有管理员的权限,否则就会出错
参考文章
使用 MSBuild 以特定的 NET Framework 为目标
MSBuild Task Reference
使用MSBuild自动编译发布你的ASP.NET应用程序
重启IIS命令行iisreset
如何使用 Appcmd.exe 命令行工具启用和配置 Internet Information Services 7.0 中的 HTTP 日志记录和其他功能
IIS(IISReset.exe)命令行
Create a Web Site (IIS 7)
Configuring-IIS-7-command-line-Appcmdexe
Getting Started with AppCmd.exe
出自:http://blog.csdn.net/xuexiaodong009/article/details/7473681
- 自动发布web应用程序或者网站
- 自动发布web应用程序或者网站
- IIS发布多个WEB网站应用程序
- silverlight 应用程序在ASP.NET Web网站或者Web应用程序里部署
- vs2012 发布web应用程序
- Web 客户端 网站发布
- web Deploy网站发布
- Tomcat发布Web网站
- Web应用程序和Web网站
- C#Web应用程序的发布
- win8 vs2012发布Web应用程序
- Web应用程序的发布问题
- 牛腩新闻发布系统——web应用程序与网站的区别
- 续接上篇 cc.net 自动发布web应用程序 配置文件的替换
- 网站与WEB应用程序区别
- Web应用程序开发查询网站
- VS2010 Web网站发布详解
- VS2010 Web网站发布详解
- 基于BOA的WEB服务的搭建
- 自己收集的比较好的hadoop博客
- ffmpeg demexing.c 源码编译
- ruby on rails 入门笔记
- MFC对话框程序中使用OpenGL
- 自动发布web应用程序或者网站
- Java多线程-线程的同步(同步代码块)
- 2014机器学习方面会议
- Android GestureDetector手势识别类
- C++深入体验之旅十一:类(上)
- 查看Linux版本系统信息方法汇总
- S3C6410时钟初始化
- 自动升级的原理及实现
- 黑马程序员之基础加强之IDE基础知识和Java5新特性