2

我目前正在研究和实现将我们的MVC和webApi项目部署到生产环境的自动方法。将Web部署自动化到远程IIS服务器

到目前为止,我已经使用内置于Visual Studio 2012中的发布工具来取得良好效果。通过在IDE中运行这一功能,我可以在生产服务器上获得并运行正确的文件和IIS配置。然而,我想要实现与此相同的功能,但通过命令行或PowerShell可以运行脚本,并自动部署2个网站。

我试图通过运行一个命令行脚本,如要做到这一点:

msbuild MyProject.csproj /p:DeployOnBuild=true;PublishProfile=MyProfile 

,这生成项目,并在此项目的OBJ文件夹中的包。这是否是正确的方法,如果是这样,我该如何将这个软件包自动部署到远程服务器?

+0

完整的源代码示例工作任何有关它的最终解决方案? – Kiquenet 2013-04-30 14:21:27

回答

3

这里是每当我要部署Web应用程序我用的功能:

function MSBuild-Publish-Web-Service 
{ 
    param (
     [parameter(Mandatory = $true)][string] $WebProjectFile, 
     [parameter(Mandatory = $true)][string] $DestinationDir 
    ) 

    Write-Host "`t`t$($MyInvocation.InvocationName): Publishing web service from $SourceDir" 

    try 
    { 
     $Error.Clear() 
     $MsBuildPath = "$env:Windir\Microsoft.NET\Framework\v3.5\MSBuild.exe" 

     if (!(Test-Path $MsBuildPath)) 
      { throw "Could not find $MsBuildPath" } 

     $res = [string](. $MsBuildPath "$WebProjectFile" /verbosity:minimal "/t:ResolveReferences;_CopyWebApplication;publish" /p:Configuration=Debug /p:OutDir="$DestinationDir\bin\" /p:WebProjectOutputDir="$DestinationDir") 

     if ($res.Contains("error")) 
      { throw $res } 
    } 

    catch 
    { 
     Write-Error "`t`t$($MyInvocation.InvocationName): $_" 
    } 

    Write-Host "`t`t$($MyInvocation.InvocationName): Web service published" 
} 
相关问题