VSO Copy website static files and binaries (not C# files) - continuous-integration

I am trying to set up continuous integration on my server using Visual Studio online.
Created a new agent pool.
Installed and configured a new build agent that I added to that agent pool.
Then I trigger a new build of my code to be handled in my agent pool.
I manage to build it but how to set up the task "Copy and publish build artifacts".
My goal here is to just copy the final website files e.g. binaries, images, cshtml, but NOT all files such c# files. Well sort of like the "Right-click > publish" operation in visual studio.
What value do I need to enter in "Copy root" field? (please see image below)

The documentation is located at: https://msdn.microsoft.com/en-us/Library/vs/alm/Build/scripts/variables
It all boils down to what the output path for your binaries is. If you're not overriding it via an MSBuild argument, $(Build.SourcesDirectory) with a value of **\bin\* will probably get you what you're after.
For a web application, make sure you're building with appropriate MSbuild arguments (something along the lines of /p:OutDir=$(build.stagingDirectory) /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true should do the trick). This will get you a _PublishedWebsites folder in $(Build.StagingDirectory).
Then all you need to do is publish Copy Root of $(Build.StagingDirectory) and Contents of **\_PublishedWebsites\*
Keep in mind that Publish Build Artifacts means publish build artifacts to VSTS or a file share, not deploy build artifacts to a web server

Related

How do I include a license file when when doing an ASP.net core build and publish in an Azure Devops Pipeline?

In my .net core 5.0 webapp, I have a file license.dat, which enables use of a paid component. In visual studio, the file is set to "COPY ALWAYS" for "Copy to Output Directory".
If I build and run my project locally in Visual Studio - or publish it locally to a folder - the file is included in the output.
If I run ´dotnet publish´ locally, the file is also included in the output.
However, when using an Azure Devops pipeline, the file is left out of the build artefact.
How can I make sure the file is included in the build artefact produced by the Azure build pipeline?
you can use Copy Files task in Azure build pipeline. you need to add new task copy file and set the source and destination folder. This is how to do using azure classic build pipeline.
How to add new copy task
copy task settings

TFS 2015 Visual Studio Build - Package .zip not being created

I'm trying to build my solution and package up the web app into a web deploy (.zip) package to be deployed.
I've added the Visual Studio Build step with the following MSBuild Arguments:
/p:DeployOnBuild=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\"
And I've set up the Copy and Publish Build Artifacts step to copy all .zip files to the drop folder.
The build completes successfully but nothing is copied to the drop folder because there are no .zip packages that get created.
So when I look on the TFS server, the only thing in the 'a' folder is an empty 'drop' folder. And in the 's' folder is the solution directory with a PrecompiledWeb folder in it. Not sure what that is but it doesn't look like the deployment package (and it's not a .zip).
Any ideas?
I have tried the same on VS2015 MVC web application using VSTS and TFS 2015.2.1 both. I had to do a slight change to the Build arguments in Visual Studio build. That is removing the trailing "\" in /p:PackageLocation="$(build.artifactstagingdirectory)\".
Here is the argument I passed to Visual studio build step
/p:DeployOnBuild=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)"
Then I used Copy and Published Build Artifacts (Deprecated in VSTS you should use Copy task and Publish task instead of this task) as shown below
This gives me output as below.
First suggest you manually remote in the build agent and build the project through MSBuild command line with arguments to see if the project builds properly.
This will narrow down the issue is related to the environment on your build agent or your build definition.
You should directly use /p:PackageLocation=$(build.stagingDirectory
Besides since you have multiple assemblies that are referenced in the web app. Please also double check dependencies that are building in the correct order or referenced correctly.
Make sure the ASP.NET development workload of Visual Studio is installed.
If DeployOnBuild is having no effect, you may need to install the ASP.NET Development "workload" with the VS setup tool.
There are specific .targets files that, if they don't exist, cause these parameters to be silently ignored. Installing this adds those .targets and the parameters become active, allowing the .zip to be created.
For me (VS 2017) the relevant target file (or one of them, anyway) that was missing but is needed is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets
If it is missing, you'll need to install as above, and if it is there, then you have a different problem. ;)

Visual Studio Team Services Basic Build and Deploy

I am trying to get a very basic build and release process going using Visual Studio Team Services.
I have created a bare bones Build that uses all default steps and settings for "Visual Studio".
Looks as though my problem is that no files are being copied in the "Copy Files To" step. it's Contents field = **\bin\$(BuildConfiguration)** (by default)
My project isn't being built to a bin directory though so no files are found to copy.
How do I get my web application project via Team Services to package only required files to a location so team services can find and copy only those required to deploy?
I was missing the following "MSBuild arguments" in the MSBuild task which does the website packaging for me.
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\"

Release website via FTP on VSTS

I am using VSTS (VSO previously) to handle the entire project and would like to do automated releases (builds are already in place) of the website that is not hosted on Azure. Thus I need to use FTP.
As I understand it I should be able to use cURL to accomplish this, but all I have been able to do is transfer all files needed without keeping the much needed file structure.
Has anyone found a way to use FTP to transfer files in the file structure? And if so, how?
You need to use "Batch Script" task and create a batch script to upload the files by curl. Refer to this question for details: Upload folder with cURL and FTP using Batch file on Windows?
If your website is hosted on a Windows Machine, you can use "Windows Machine File Copy" task to upload the files. This task keeps the folder structure.
And also, you can generated web deploy packages during the build by adding following MSBuild arguments in "Visual Studio Build" task in the build definition and upload it to build artifact.
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
Then in "Release", adding a task to run the "xxx.deploy.cmd" which is included in the build artifacts to deploy the files to your server. (Make sure your server has installed "Web Deploy Remote Agent Service")
xxx.deploy.cmd [/T|/Y] [/M:ComputerName] [/U:UserName] [/P:Password] [/G:UseTempAgent] [Additional msdeploy.exe flags ...]

Building zip file with Visual Studio

I am using Visual Studio 2013 to develop a website. The website is on github, and I have a server for continuous integration set up with Teamcity.
I am trying to get the website to automatically deploy to AWS when I change it on github. I have Teamcity hooked up, but the AWS CLI is having some issues, so I need to compile the solution in Teamcity into a zip file so that I can deploy to AWS using a workaround.
I've tried editing the project files for an MSBuild fix...I managed to get a zip file output. However, I ran into problems with general compilation.
What I am wondering is, since I can publish a website package from Visual Studio, is it possible to compile as if I was publishing using the build commands from TeamCity (or the command line) so that the result is the compiled project and the website files needed to run the site in a zip file?
you can create a zipped artifact in TeamCity. Simply build the project then set the artifacts for the build like this:
outputFolder\*.dll=>myzipfile.zip
outputFolder\*.whatever=>myzipfile.zip
etc
obviously you'll need to change outputFolder to be where the files are actually output by the build and the patterns to macth the files you want

Resources