Powershell 自动将Web部署到远程IIS服务器
我目前正在研究并实现一种将MVC和webApi项目部署到生产环境的自动方法 到目前为止,我使用了Visual Studio 2012内置的发布工具,效果良好。通过在IDE中运行它,我可以获得正确的文件和IIS配置,并在生产服务器上运行。然而,我希望实现与此相同的功能,但通过命令行或powershell,这样就可以运行一个脚本,它将自动部署这两个网站 我尝试通过运行命令行脚本来实现这一点,例如:Powershell 自动将Web部署到远程IIS服务器,powershell,command-line,msbuild,visual-studio-2012,webdeploy,Powershell,Command Line,Msbuild,Visual Studio 2012,Webdeploy,我目前正在研究并实现一种将MVC和webApi项目部署到生产环境的自动方法 到目前为止,我使用了Visual Studio 2012内置的发布工具,效果良好。通过在IDE中运行它,我可以获得正确的文件和IIS配置,并在生产服务器上运行。然而,我希望实现与此相同的功能,但通过命令行或powershell,这样就可以运行一个脚本,它将自动部署这两个网站 我尝试通过运行命令行脚本来实现这一点,例如: msbuild MyProject.csproj /p:DeployOnBuild=true;Publ
msbuild MyProject.csproj /p:DeployOnBuild=true;PublishProfile=MyProfile
这将构建项目并在项目的obj文件夹中创建一个包。这是正确的方法吗?如果是,如何使此包自动部署到远程服务器?以下是我在部署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"
}
是否有完整源代码示例的最终解决方案?