VSTS Publish Artifact empty, MVC web app deploy on-prem - azure-devops

Trying to use a hosted build agent and an on-prem release agent.
Project is an ASP.Net MVC web app within a solution with other projects.
The build completes successful but there is nothing in the artifact folder so the release does nothing.
[ update 5/22/2018]
What I need to do is publish to some location relevant to the hosted agent, then in my on-prem release agent, be able to use a copy_files task to simply copy those files to a unc path.
[ update 5/23/2018]
Using these msbuild arguments on the build task, I was able to get a zipped folder containing the published files. The only problem now is that the files are in a deeply nested structure. So I either just need to unzip them on a release task, or prevent them from being zipped.
/t:My_MVCWeb_Project_Name /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
Build log
Build task (Hosted VS 2017 agent). The /t parameter is followed by a project_name.
Publish task of Build definition
Release definition, with just a copyfiles task (this runs on-prem)

You need to use the default MSBuild Arguments in Build step since you use ASP.NET build template:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"
Or you need to add a Copy Files task before Publish Build Artifacts
to copy the files you need to path $(build.artifactstagingdirectory):

Related

Deploying Multiple WebJobs from the Same Project in a Azure DevOps Release Definition?

So the way that we've structured our code is that we've got several projects in our solution that each have multiple webjobs. We've configured a manual way of releasing these multiple webjobs using the run.cmd files and copying over the pertinent run.cmd file to the root folder depending on which webjob we're trying to release.
I'm wondering if there is any way to do this via a build/release definition in Azure DevOps without having to tear apart the multiple webjobs into individual projects. These multiple webjobs also all live in the same App Service.
What you have done is the simplest way at present, you could just clone the process in Azure DevOps Build/Release Pipeline. There is not any way to do this in Azure DevOps without having to tear apart the multiple webjobs into individual projects.
We've configured a manual way of releasing these multiple webjobs
using the run.cmd files and copying over the pertinent run.cmd file to
the root folder depending on which webjob we're trying to release.
For example, in your build solution step define (add some copy file step to copy necessary files) :-
Visual Studio Build (Solution: ***.sln, MSBuild Arguments:
/p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\")
Publish Build Artifacts (Path to Publish: $(build.artifactstagingdirectory); Artifact Name: drop; Artifact Type: Server)
Create a release definition for this build definition and add a task
Azure App Service Deploy
Select your Azure Subscription and App Service name;
Select your Package or Folder:
$(System.DefaultWorkingDirectory)**\WebJob1.zip
You can similary create another Azure App Service Deploy task for WebJob2.zip and deploy as many webjobs you want through a single build and release pipeline.

Azure Devops deploying Azure C# Function

I'm failing to use the Azure Devops Release management to deploy my Azure Functions.
Build
In the build pipeline, I've got two tasks:
dotnet publish
publich release artifact
This step succeeds
The artifact is published into /drop/a.zip
Release
In this step I have a Dev environment.
and a single task:
Azure Function App Deploy.
Credentials and which app to deploy to is specified.
There is a path specified to the release artifact like so:
I can even browse the path with the browse button in that image. and navigate to and pick the correct zip there.
But once this task runs. it all ends with a
##[error]Error: No package found with specified pattern: D:\a\r1\a\DotnetFunctions-CI\drop\a.zip
I am aware there are other questions here on SO bringing up the same question. however the answers I've seen there does not solve the issue here.
What am I missing?
I've had issue with the release pipeline not finding an artifact. What I've started doing is using the double wildcard search instead of the full path.
That is in my Deploy Azure App Service task inside the release pipeline.
My azure function works:
In Build :
Visual Studio Build Task :
Add following arguments in MSBuild section :
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\$(BuildConfiguration)\\"
here is my build and release:
Build Configuration:
Release :

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

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

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.

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))