0

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.

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

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?

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.

Alan
  • 1,587
  • 3
  • 23
  • 43
  • Try adding VisualStudioVersion parameter described in https://stackoverflow.com/questions/14175910/deploying-to-ftp-from-command-line-using-msbuild-on-vs2012-not-working-no-error – Steve Kennedy Jul 10 '17 at 17:24
  • That was an interesting post and linked blog, but sadly doesn't seem to help. It seemed to be speaking to someone not getting an error and that param would enable the error feedback. But the post did seem to support the idea that maybe MSBuild won't do my publish profile because it is FTP, although it is an old post and things may have changed since then. – Alan Jul 10 '17 at 18:15

1 Answers1

1

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

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

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

Update:

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/

Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
  • Line 3 above, where is $filePath being set? The linked Michael Seirer's article was very cool (Thanks!), but he was trying to upload a single zipped file, and he also seems to leave some steps out. It's not obvious to me how his Tip 7 fits together. In my case where I'm uploading an entire website structure, somewhere I have to tell the script where my website file/folders are; I assume this is via $filePath, but I don't see where $filePath gets assigned. – Alan Jul 11 '17 at 23:38
  • 1
    @Alan 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. You can check if that worked,you can also reference another script here to upload the directory : https://www.kittell.net/code/powershell-ftp-upload-directory-sub-directories/ – Andy Li-MSFT Jul 12 '17 at 09:39
  • Thanks! That last example was perfect. I'm not finished, of course, as I need to go through it and adjust it the way I need it, but it did upload my website using FTP. I'll post my script here when I'm finished to round out the solution for others with the same issue I had. Regarding the first script you posted, I was never able to get past the OpenRead command; kept getting a permission error which my research showed could be due to any number of reasons. But the kittell sample was much easier to follow, and it worked 'out of the box' as well. Thx again! – Alan Jul 12 '17 at 14:44
  • Just to wrap this post up, the power shell script at the kittel.net site was perfect. After upgrading to VS/TFS 2017, the Build Definition process is so much improved that integrating power shell as you advised was very easy once I got familiar with that script. Thx! – Alan Oct 19 '17 at 19:43