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

查看:14
本文介绍了如何将 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"

这是构建返回的错误:

C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0WebDeployMicrosoft.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.

推荐答案

正如错误消息中提到的 FTP is not supported on msbuild command line.

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!"

您也可以参考这篇文章:使用 TFS Deployer、PowerShell 和 FTP 部署网站

You can also reference this article: Deploying Web Sites using TFS Deployer, PowerShell and FTP

更新:

这只是一个示例,$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天全站免登陆