Deploying .NET with Jenkins/Hudson - visual-studio-2010

I've been using Jenkins/Hudson CI for deploying my .NET web site project. I've been using the MSbuild plugin to build my project, and then xcopy to copy it out to the server.
I've noticed if I use the publish feature in Visual Studio I get a different set of files. I've got the config transforms working, but I end up with all the .cs files and a winmerge compare shows the binaries being different.
So, I'd like to either get Jenkins working just like the publish feature, or confirm that an xcopy deploy is functionally the same thing.

I've had good experiences with using Web Deploy and as a final build step with Jenkins running a bat file containing:
msdeploy.exe -verb:sync -source:package=%PACKAGE% -dest:auto,ComputerName=%TARGETHOST%
You'll have to install the web deploy package on your build server and the extention on IIS.

I'm using the MSBuild Jenkins plugin to build and then deploy the project. As mentioned in other answers, you need to have Web Deploy installed.
In the project configuration page in Jenkins, you need to add the following to the Command Line Arguments field:
/p:Configuration=Debug /p:DeployOnBuild=true /p:PublishProfile=publishProfileName
Of course, you need to first create the publish profile, either in VS or by exporting it from IIS and you also need to specify the solution file path in the MSBuild Build File field.

Related

Deploy Azure WebJob using VSTS

I'm having some issues deploying an Azure WebJob using Visual Studio Team Services (VSTS).
The WebJob seems to be deployed successfully but it breaks the Azure website that is hosted in the same App Service! I don't have this problem if I deploy using VS2013.
This is my build task that generates the WebJob deployment package:
And this is my deployment task:
There are no errors when I deploy the Azure WebJob. If I go to the Azure Portal I see the WebJob is there, and it runs successfully. WebJob files are copied into the wwwroot\App_Data\jobs\triggered\RemoveExpiredDids folder as expected, but the problem is that some other files will be copied into the wwwroot\App_Data\bin folder, which will break the existing website that was already deployed into that App Service!!!
So I decided to find out why this was happening. After downloading and extracting the deployment package I saw there are 2 folders (app_data and bin) and the scheduler file (settings.job):
This explains why some assemblies are coppied into the wwwroot\App_Data\bin of the App Service. The strange thing is that this doesn't happen when deploying from VS2013!!! I took a look into the MSBuild log and found the following line:
Object dirPath ([app service name]\bin) skipped due to skip directive 'SkipBinFolderOnDeploy'.
Concluding, bin folder is included when deploying the Azure WebJob from VSTS but is excluded when deploying it from VS2013.
So my question is: how to prevent the bin folder from being deployed when using VSTS? Is there any MSBuild parameter/flag to do this?
I've had issue with this particular problem as well.
The latest method I found is using Web Deploy Operation Settings , -skip:Directory= (in this case it would be -skip:Directory='\\bin') when you create your azure deploy task in the release definition (Additional arguments). I've seen that this indeed excludes the bin folder from the update actions (result).
Let me know if this helps you in any way.
Refer to these ways to deploy webjob to azure:
Modify Visual Studio Build task to deploy webjob with FileSystem (MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\WebJob" /p:DeployDefaultTarget=WebPublish)
Add Delete Files task to release definition to delete bin folder (Source Folder: $(System.DefaultWorkingDirectory)/WebJobVnext/drop/WebJob); Contents:bin)
Modify Azure App Service Deploy task (1. Uncheck Publish using Web Deploy option. 2. Package or folder: $(System.DefaultWorkingDirectory)/[artifact name] /drop/WebJob)
I was finally able to fix it, thanks #starain-MSFT for pointing me in the right direction. I had to make some minor changes, though. This is the task that creates the deployment package:
MSBuild arguments:
/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:DeployDefaultTarget=WebPublish /p:Configuration=$(BuildConfiguration) /p:OutputPath=.\bin\ /p:publishUrl="$(build.artifactstagingdirectory)\temp\WebJob"
The difference here comparing to #starain-MSFT answer is that I had to add the /p:OutputPath= parameter, otherwise I'd get the following error:
The OutputPath property is not set for project
After generating the package, I delete the bin folder and zip it (this reduces the build time).
This is my deployment task:
Please note that $(DeploymentPackagePath) is the path to the zip file that contains the deployment package, as mentioned before. It doesn't matter if you deploy the package as a zip file or if you unzip it and deploy the folder, it works both ways.

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 ...]

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

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

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

teamcity is not executing msbuild command

I have a configuration in teamcity that package and deploys. I am using the following to package and deploy on a remote server
/M /P:Configuration=%env.Configuration% /P:DeployOnBuild=True
/P:DeployTarget=MSDeployPublish /P:MsDeployServiceUrl=%env.TargetServer%/MsDeployAgentService /P:MSDeployPublishMethod=RemoteAgent /P:CreatePackageOnPublish=True /P:Username=%env.username% /P:Password=%env.password%
It is not doing any thing just building the project. Any idea what I am missing here. Process that makes a package is missing from build. Validating Web Deploy package/publish. plz help
Have a look at the You're deploying it wrong! TeamCity, Subversion & Web Deploy series. My suspicion is that either Web Deploy is not configured correctly on the server (i.e. service not started) or that your credentials are incorrect. Try going through the steps in the series above and getting the basics to work work leaving TeamCity until the very end. Get it deploying from Visual Studio then the command line and work from there.
Here is my deployment string for our TeamCity publish:
/t:ResolveReferences;_CopyWebApplication /p:OutDir=..\..\..\build\Framework.Production\bin\;WebProjectOutputDir=..\..\..\build\Framework.Production\
I believe the part you need is /t:ResolveReferences;_CopyWebApplication

Resources