下面是在btnet的项目中使用的发布脚本,供参考吧!
根据各自的功能需要,自行修改。
主要功能
1)在bat中发布Windows服务
2)在bat中创建数据库,并执行建表脚本
3)在bat中发布并创建IIS站点
4)在bat中使用powershell配置Web.config文件
5)在bat中启动浏览器,浏览站点
6)在bat中删除站点
7)在bat中删除数据库
REM this might work for you. It worked for me on Windows 7 Pro. C:WindowsMicrosoft.NETFrameworkv2.0.50727installutil %CD%tnet_servicein eleasetnet_service.exe
@echo off echo You must run this as Administrator. echo You'll need to know a SQL Server username and password that works with SQL Server security (not a Windows user) echo The script assumes a SQL Server instance of localSQLEXPRESS that works with both Windows and SQL Server security. echo set BTNET= set SQLUSER= set SQLPSWD= set /p BTNET=Enter name of btnet instance. Hit enter for default "btnet": set /p SQLUSER=Enter SQL Server username. Hit enter for default "sa": set /p SQLPSWD=Enter SQL Server password: if "%BTNET%"=="" set BTNET=btnet if "%SQLUSER%"=="" set SQLUSER=sa @echo on REM create the iis7 application C:WindowsSystem32inetsrvappcmd.exe add app /site.name:"Default Web Site" /path:/%BTNET% /physicalPath:"%CD%www" REM create the database ::sqlcmd -S localhostSQLEXPRESS -Q "create database %BTNET%" sqlcmd -S . -Q "create database %BTNET%" REM create the tables ::sqlcmd -S localhostSQLEXPRESS -d %BTNET% -i "%CD%wwwsetup.sql" sqlcmd -S . -d %BTNET% -i "%CD%wwwsetup.sql" REM modify Web.config powershell "$hostname = hostname; Get-Content %CD%wwwWeb.config | ForEach-Object {$_ -replace '127.0.0.1', $hostname } | ForEach-Object {$_ -replace 'database=btnet', 'database=%BTNET%' } | ForEach-Object {$_ -replace 'user id=sa;password=x', 'user id=%SQLUSER%;password=%SQLPSWD%' } | Set-Content %CD%wwwWeb.config2; Move-Item %CD%wwwWeb.config %CD%wwwWeb.config.$(Get-Date -Format 'yyyyMMdd_HHmmss').bak" ::del %CD%wwwWeb.config rename %CD%wwwWeb.config2 Web.config REM if all goes well, show the web page. start http://localhost/%BTNET%
rem 删除站点 C:WindowsSystem32inetsrvappcmd.exe delete app /app.name:"Default Web Site/%BTNET%" rem 删除数据库 sqlcmd -S . -Q "alter database %BTNET% set single_user with rollback immediate;drop database %BTNET%"