VSTS - MVC Web app deploy task is deprecated. How to deploy to test server on prem - azure-devops

Setting up a Release definition task to deploy a MVC web app to a test server (on prem). Typically I have done this a FileSystem publish via a Visual Studio publish profile. What task can I use in VSTS to achieve the same thing, assuming I already have a working agent setup on the test server and a successful build?
The app is actually setup as a website on the test server, not a virtual app under another website. Looking at adding the "IIS Web App Deploy" task, VSTS reports that this task is "deprecated, so what is the suggested replacement for this?
I suppose I could use the Windows file copy task, but the build artifacts are zipped. What would I need to use if I went this route?

You can use Visual Studio Build task with /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish MSBuild Arguments to publish web app to artifact folder (e.g. {agent working folder}/1/a).
You also can specify the publish profile directly /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:PublishProfile="{publish profile name}";publishUrl="$(build.artifactstagingdirectory)"
With FileSystem publish method, the published files are in a folder, not zipped, but you can zipped the folder through Archive files task.
Also you can extract files through Extract files task, so you can copy extracted files through Window machine file copy task to the corresponding web site path.
On the other hand, you can deploy the web app through WinRM-IIS Web App Deployment task.

Related

.NET Core Webjob does not publish when deployed through CD in VSTS

I have a dot net core 2.0 console app which I need to publish in Azure as webjob through continuous build and deployment in VSTS. I have created a web app already in Azure and defined CI and CD tasks in VSTS for the console app's project.
The issue is that whenever these tasks run, webapp gets deployed successfully but the webjob does not get deployed. However, it gets deployed when I use the artifact (zip folder created after build process) and upload it manually to Azure webjob section.
I think deploying the artifact using powershell script might be a solution but I have tried zipdeploy API of Kudu as well but to no use. Can someone please help or point me to a reference for extracting the artifact generated from build process and deploy it using CD tasks so that the webjob gets published alongwith webapp.
With general web application, if you link web job project to the web (right click web app in Visual Studio > Add > New Azure WebJob project/Existing project as WebJob), you can refer to these steps below:
Create a new build definition
Add NuGet Tool Installer task
Add NuGet restore task (Path to solution, packages.config: ***.sln)
Add Visual Studio Build task (MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\")
Add Publish Artifact task (Path to publish: $(build.artifactstagingdirectory))
Queue build
Create a new release definition
Add Deploy Azure App Service task (Package or folder: {web app zip file path}; Choose Publish using Web deploy)
Otherwise:
Create a new build definition
Add NuGet Tool Installer task
Add NuGet restore task (Path to solution, packages.config: ***.sln)
Add Visual Studio Build task (/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\" /p:DeployDefaultTarget=WebPublish
Add necessary task to build web job project (e.g. Visual Studio build)
Add Copy Files task to copy web job’ build result to appropriate folder in web app published folder ($(build.artifactstagingdirectory)) (App_Data/jobs/continuous for continuous webjobs or App_Data/jobs/triggered for scheduled and on-demand WebJobs)
Add Archive Files task (Root folder or file to archive: $(build.artifactstagingdirectory); Archive file to create: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip)
Add Publish Artifact task
Create a new release definition
Add Deploy Azure App Service task (Package or folder: {web app zip file path}; Choose Publish using Web deploy)

Setup publish to folder using VSTS

I was using publish to folder option through Visual Studio by right-clicking on the project -> publish -> publish to folder. Result was always ready-to-copy project with applied transformations.
I wanted to automate this process using VSTS and have setup build on VSTS.
I used next steps:
- NuGet restore
- Build solution
- Publish Build Artifacts to $(build.artifactstagingdirectory)
- Windows machine file copy from $(build.artifactstagingdirectory) to remote machine using admin login and password
And finally I'm getting zip package on remote machine with complicated folder structure without applied transformations inside at all.
What is wrong? How I can setup same "publish to folder" as in Visual Studio but using VSTS?
Add below Target to your .csproj to enable transforming config files
<Target Name="TransformConfigFiles" AfterTargets="AfterBuild" Condition="'$(TransformConfigFiles)'=='true'">
<ItemGroup>
<DeleteAfterBuild Include="$(WebProjectOutputDir)\Web.*.config" />
</ItemGroup>
<TransformXml Source="Web.config" Transform="$(ProjectConfigTransformFileName)" Destination="$(WebProjectOutputDir)\Web.config" />
<Delete Files="#(DeleteAfterBuild)" /></Target>
In your build solution step add the following build arguments "/p:TransformConfigFiles=true" will make the config transformation using the above added target to .csproj
/p:TransformConfigFiles=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:OutDir="$(build.stagingDirectory)"
Then you can use a publish step to publish your $(build.stagingDirectory) contents. You can use $(build.stagingDirectory)_PublishedWebsites as path to publish if you only need the website output.
This will allow you to get the ms deploy package as well as xcopy deploy published website files.
You can use copy files task before the publish task to copy any additional files if you have any to $(build.stagingDirectory) and get them published as build artifacts.
Use VSTS release management with deployment groups to deploy your application to target server. You can use IIS deploy task to deploy to IIS using ms deploy package. If you are using web deploy package you can use a parameters.xml in your web app to get the web config parameters assigned to .setparameters.xml so that you can change values in the deployment time using IIS deployment task.
You are publishing web application through File System method, it is based on the specified configuration (e.g. Debug, Release) to transform web.config. So you need to check which configuration you specified in build solution task (e.g. Visual Studio Build task)
Simple tasks:
NuGet Tool Installer task
NuGet restore task
Visual Studio Build task (MSBuild Arguments: /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish; Platform: $(BuildPlatform); Configuration: $(BuildConfiguration)) Note: BuildPlatform and BuildConfiguration are build variables. It will publish web app to artifacts directory ([agent working folder]/1/a)
Publish Build Artifacts (Path to publish: $(build.artifactstagingdirectory))

VSTS CI CD for desktop apps

How can I achieve CD (Continuous Delivery) for winform applications in VSTS (Visual Studio Team Services)? Currently this is what I have in my Visual Studio Solution file
1) A winform project
2) A Windows setup and Deployment project
So every time I build a winform project, I do the following steps (and I need CI / CD for exactly these)
1) Build Setup and Deployment project, which takes Build output of Winform project and creates and EXE / MSI
2) I take this MSI file and use NSIS to embed it inside EXE
3) I run SIGNTOOL from command prompt and digital sign the EXE
4) I upload this signed EXE to my website
Now how can I use CI / CD pipeline to automate the above or is it not possible for my case? I am confused. I can't find any material for winforms, all are for web apps.
Thanks
You will obviously need some sort of desktop deployment strategy. The easiest is to be using xcopy. Other alternatives include frameworks like ClickOnce, Windows Installer or Squirrel to name a few. I have a number of corporate apps that use Clickonce that I have deployed using vsts.
Now I am unable to understand how will VSTS help me with this?
Use VSTS to build the software first and include additional tasks to package your app. In my case, I use devenv.exe to generate ClickOnce packages, but you can include custom tasks by using powershell. The artifact of the build should now be the "packaged app".
Then use the VSTS deployment to copy the "package" to some kind of hosting server from where your users can download the package. That could be either a web server or a fileserver or any location appropriate for your deployment strategy.
In this context, VSTS is an orchestration tool. It helps to trigger actions for you.
See Deploy an agent on Windows to see how to setup an on-premise agent.
To build and deploy the way as you used in VSTS, you can use below steps:
Create a repository (Git or TFVC) and push your solution in the repository.
Add build/release definitions.
With CI build, enable the Continuous Integration in Triggers Tab. With CD deploy, enable Continuous deployment trigger in Pipeline Tab. The process for CI build and CD deploy, you can refer CI/CD.
Add related tasks in your build/release definition.
Build VS Installer task: build setup project with msi file.
Nsis Build Task: embedded msi file in exe.
Command Line task: to execute the signtool command. Since Hosted agent has not signtool.exe, so you should use private agent which has the signtool.exe on the machine.
Copy files task, Copy Files Over SSH task or Windows Machine File copy task: upload the file exe to your web server.

How to publish WebApp as Azure Virtual Application from TFS Release (vNext)

I need to publish 3 webapp to azure using release manager from TFS, and I need all of these 3 apps inside wwwroot subfolder:
wwwroot\app1
wwwroot\app2
wwwroot\app3
This is because I have a azure virtual application pointing to each of this folders.
I have a release for each app. Each app should deploy not to wwwroot, but to a folder inside wwwroot (app1, app2 or app3).
At this moment what I'm doing as a workaround is deploying a package (zip) with the name of the folder that I need (app1, app2 or app3), however, this is just a workaround, because if I activate "clean" in the release task, this clean all wwwroot folders and clean the other apps.
Is there anyway to deploy using some Task to a specific folder instead root folder (wwwroot)? Or, is there a way to deploy to azure virtual application?
If not, is it possible to send me a powershell command to delete a specific folder in the wwwroot?
I'm using "Azure Web App Deployment" task that uses Publish-AzureWebsiteProject PS command, but I don't know if it's possible to send some argument to send this to a specific folder inside wwwroot? Is there some argument to do that?
Thank you all for the availability
You could directly use the AzureRM Web App Deployment task released by Microsoft which allows for virtual directories.
Update
It's a build-in task called Azure APP Service Deploy
The task you are using-- Azure Web App Deployment is deprecated.
NOTE: This task has been deprecated. To update Azure App Services using Web Deploy or Kudu REST APIs, use the Azure App Service
Deploy task.
We recommend you replace the Azure Web App Deployment task with the
Azure App Service Deploy task in all your build or release
definitions.
I found another solution. Using cURL to upload by FTP and I can control each individual folder.
Anyway, if someone knows how to deploy directly to a virtual app directory, please provide answer :)
Thank you

VSTS: Release Management Deploying Artifacts to IIS on Premise

I am using VSTS Release management to deploy artifacts to IIS websites. I have several Web applications and web services to be deployed. So, i am trying to figure out what sort of tasks that best fits my situation.
I have created a build definition with Visual Studio Build Task for projects as this one:
which works fine but i need to add a task for copying the artifacts Under IIS Website Directory.
The other approach is to use IIS web deployment as a task in Release definition, so I created the build definition as:
However, it expects a Publish Profile (the build fails because it can't find it). I don't need to create a publish profile for each project in the application because this would be too much work.
Is there is a workaround for that or what is preferred approach for this?
You can update your build definition to generate a web deployment package and upload it to artifacts. And then in Release Management, add a task to run "projectname.deploy.cmd" in the deployment package to deploy it to your IIS server. Refer to this link for details: How to: Install a Deployment Package Using the deploy.cmd File Created by Visual Studio.
And you can also enable FTP Publishing on your IIS server and add a task in your release to publish the artifacts via FTP. You may need this task:
FTP Uploader.
My Continuous Delivery with TFS / VSTS – Server Configuration and Application Deployment with Release Management blog post (with reference to some previous posts) has all the details you need for deploying your artefacts to target nodes using Windows Machine File Copy tasks then use PowerShell on Target Machines tasks to get them in to correct locations and to do token replacement and anything else that's required.
I would recommend using PowerShell DSC so that IIS is properly configured before deployment but that's not required. Where possible for web apps I favour keeping things very simple by creating artefacts that contain all the web files that are needed for a particular folder and then just using plain xcopy for the deployment.
If you need more control you can also use my MSDeploy VSTS extension to deploy a MSDeploy package
https://marketplace.visualstudio.com/items?itemName=rschiefer.MSDeployAllTheThings
https://dotnetcatch.com/2016/04/20/msdeployallthethings-vststfs-extension-is-public/