如何将 FTP 网站部署添加到 VS2015/TFS2013 构建过程

How can I add FTP website deployment to a VS2015/TFS2013 build process

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

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

这是构建返回的错误:

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.

错误似乎是 self-explanatory,但作为构建配置的新手,我需要询问以确保没有其他原因导致我收到此错误。

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

我还想问一下,如果这个特定的 IDE 组合(即 VS2015/TFS2013)无法处理我的发布配置文件(似乎是这样),是否有替代方案我可以使用在构建后合并自动部署的方法?

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

更新:我更改了标题和一些文字以更能反映需求。

正如错误消息中提到的那样 FTP 不支持 msbuild 命令行。

您应该切换到 PowerShell 解决方案,您可以参考下面的 PS 示例以通过 FTP 上传构建。查看更多详细信息 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!"

您也可以参考这篇文章:Deploying Web Sites using TFS Deployer, PowerShell and FTP

更新:

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