如何将FTP网站部署添加到VS2015/TFS2013构建过程中 [英] How can I add FTP website deployment to a VS2015/TFS2013 build process

查看:186
本文介绍了如何将FTP网站部署添加到VS2015/TFS2013构建过程中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的构建操作成功.现在,我想让构建定义将站点发布到我的暂存位置.我试图使用一个发布配置文件,该配置文件可以在Visual Studio中正常运行,但似乎不适用于Visual Studio和TFS的这种独特组合.这些是我的MSBuild参数:

I have a successful build operating. Now I would like to have the build definition publish the site to my staging location. I tried to use a publishing profile that functions correctly from within Visual Studio but that doesn't seem to work with this unique combinations of Visual Studio and TFS. These are my MSBuild arguments:

/tv:14.0 /p:DeployOnBuild=true /p:PublishProfile="profileName.pubxml"

这是从构建返回的错误:

And this is the error returned from the build:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Deploy\Microsoft.Web.Publishing.Deploy.FTP.targets (42): This specific WebPublishMethod(FTP) is not yet supported on msbuild command line.  Please use Visual Studio to publish.

该错误似乎是不言自明的,但是对于构建配置而言,我是新来的,所以我需要确保没有其他原因导致此错误.

The error seems self-explanatory, but being new to build configurations I need to ask to make sure there aren't other reasons I would get this error.

我是否正确编写了MSBuild参数?一组不同的论点会改变结果吗?

Did I compose the MSBuild arguments correctly? Would a different set of arguments change the outcome?

我也想问一下,如果这个特定的IDE组合(即VS2015/TFS2013)无法处理我的发布配置文件(似乎是这种情况),我是否可以使用其他方法来合并自动在构建后部署?

I also would like to ask, if this specific IDE combo (i.e. VS2015/TFS2013) is not able to process my publish profile (as seems to be the case), is there an alternate method I can use to incorporate an automatic deploy after the build?

是否可以将PowerShell脚本添加到post build来执行FTP上传?

Could a PowerShell script be added to the post build to perform the FTP upload?

更新:我更改了标题和一些文字,以更好地反映需求.

Update: I changed the title and some text to be more reflective of the need.

推荐答案

就像错误消息中提到的那样,msbuild命令行不支持FTP.

Just as mentioned in the error message FTP is not supported on msbuild command line.

您应该切换到PowerShell解决方案,您可以参考下面的PS示例通过FTP上传构建.查看更多详细信息

You should switch to a PowerShell solution, you can reference below PS sample to upload the build via FTP. See more details here.

$ftpWebRequest = [System.Net.FtpWebRequest]::Create((New-Object System.Uri("ftp://your_ftp_server")))
$ftpWebRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile

$inputStream = [System.IO.File]::OpenRead($filePath)
$outputStream = $ftpWebRequest.GetRequestStream()

[byte[]]$buffer = New-Object byte[] 131072;
$totalReadBytesCount = 0;
$readBytesCount;

while (($readBytesCount = $inputStream.Read($buffer, 0, $buffer.Length)) -gt 0)
{
$outputStream.Write($buffer, 0, $readBytesCount)
$totalReadBytesCount += $readBytesCount
$progress = [int]($totalReadBytesCount * 100.0 / $inputStream.Length)
Write-Progress -Activity "Uploading file..." -PercentComplete $progress -CurrentOperation "$progress% complete" -Status "Please wait."
}
$outputStream.Close();
$outputStream = $null;
Write-Progress -Activity "Uploading file..." -Completed -Status "Done!"

您还可以参考本文: 更新:

这只是示例,$ filePath应该是您的发布路径,这意味着您可以使用msbuild将网站发布到本地或UNC路径,然后调用powershell从以下位置复制/上传所有文件(包括整个文件夹结构) FTP服务器的路径.如果上述脚本不起作用,您还可以在此处引用另一个脚本来上载整个目录: https://www.kittell.net/code/powershell-ftp-upload-directory-sub-directories/

That's just a sample, the $filePath should be your publish path, that means you can use msbuild to publish the website to local or UNC path, then call powershell to copy/upload all the files (including entire folder structure) from that path to FTP server. If above script not worked, you can also reference another script here to upload the entire directory : https://www.kittell.net/code/powershell-ftp-upload-directory-sub-directories/

这篇关于如何将FTP网站部署添加到VS2015/TFS2013构建过程中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆