0
votes

I am trying to deploy a .NET (not .NET Core) web api using Azure DevOps to an Azure Web App. Its a standard issue web api which i have no issues running locally or deploying via Visual Studio Code Azure Deploy extension.

I have the following YAML file. The entire pipeline runs fine without any errors. No errors in the YAML file itself.

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop    


- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
    includeRootFolder: false    

- task: AzureWebApp@1
  inputs:
    azureSubscription: 'BariBasicConnection'
    appName: 'baribasicsapiserverjune21st2020b'
    package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'      

The web app itself, when I try to load, it gives the following error.

The service is unavailable.

And, when i check the app files via Kudu, I see this in the wwwroot folder, webconfig file.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name = "Site Unavailable" stopProcessing = "true">
                    <match url = ".*" />
                    <action type = "CustomResponse" statusCode = "503" subStatusCode = "0" statusReason = "Site Unavailable" statusDescription = "Could not download zip" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration> 

At this point, I am pretty sure, I am not picking up the right folder to deploy or something but Azure DevOps focuses mostly on .NET Core and Node and I am finding it difficult to find .NET specific related solutions.

1
Try running a commandline task to export all files to the logs to find the correct path: cd "$(build.artifactStagingDirectory)" & dir /s /b that should let you find the actual path to the zip file you're trying to deploy.jessehouwing
actually, I was hoping if someone can help me with the correct default build folder to use in this situation.Jay
There is no "default path" actually... As the default includes the name of the project and can be influenced by a number of msbuild variables and project configurations. Your YAML is pretty decent default. Running the dir /s /b once should tell you the correct path to put in your YAML, then you can remove it that call.jessehouwing
i think we are missing the point here. my question is not where the build folder is going. i am trying to figure out, wherever it goes, how can i pick it up, and put it on the web app. i am already seeing the deployment files via the drop artifact, so that is all good so far.Jay
The AzureWebApp task should take care of that for you... By passing the path to the deployment zip.jessehouwing

1 Answers

0
votes

Took me a good 6 hours of browsing around like some 100 azure doc files but finally got it to work.

A few things I found out.

  • The main problem was AzureWebApp@1. That is not the deployment component for .NET projects at all.
  • Further, the packager was already generating a zip file. So, the zip and unzip components in my file is actually not required. but i left it there anyway as it is required for other projects. It took me a while to figure that out.

Here is the full YAML file.

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

# commit made to the master branch triggers the pipeline run.

trigger:
- master

# agent pool to run
pool:
  vmImage: 'windows-latest'

# standard variables for a asp.net project deployment

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

# .net needs all those nuget packages installed

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

# this is the building of the project

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

# run the unit tests 

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'


# publish the build artifacts
# this is where you get the deployment settings
# the deployment zip folder that you can later use for other things.
- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop    
    
# archive the build artifact for later processing

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
    includeRootFolder: false  

# Extract files
# Extract a variety of archive and compression files such as .7z, .rar, .tar.gz, and .zip
# just extract it as an extra step

- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '$(Build.ArtifactStagingDirectory)/**/$(Build.BuildId).zip' 
    destinationFolder: '$(Build.ArtifactStagingDirectory)/temp1'
    cleanDestinationFolder: false

# finally deploy it.

- task: AzureRMWebAppDeployment@4
  inputs:
    Package: '$(Build.ArtifactStagingDirectory)/projectname.zip'
    appType: 'webApp'
    ConnectedServiceName: ''
    WebAppName: ''

The full repo is also available here - https://github.com/Jay-study-nildana/APIServerDotNetWithSimplePasswordToken/blob/master/azure-pipelines.yml