简体   繁体   中英

Unable to deploy azure function targeting .net framework 4.8

I have a Azure function that is targeting .net framework 4.8

It's working fine when I deploy it thorough visual studio but I am trying to create a azure-pipeline.yml file for deployment. But it actually put the root level files in the artifact folder and not the ones that visual studio puts in the publish folder.

I can't find any good help for .net framework.

Here is my yaml file:

trigger:
- master
- feature/*
- hotfix/*

pool:
  vmImage: 'windows-2019'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  isMaster: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]
  isDeployableBranch: $[eq(variables.isMaster, true)]

stages:
- stage: Build
  displayName: Build and Test Package
  jobs:
  - job: Build_Test_Publish
    displayName: Build_Test_Publish
    steps:
    - task: NuGetToolInstaller@1

    - task: VisualStudioTestPlatformInstaller@1
      displayName: 'Install Visual Studio Test Platform'
      inputs:
        packageFeedSelector: 'nugetOrg'
        versionSelector: 'latestStable'

    - task: NuGetCommand@2
      displayName: 'Restore NuGet packages'
      inputs:
        command: 'restore'
        restoreSolution: '$(solution)'
        feedsToUse: 'config'
        nugetConfigPath: './'
        externalFeedCredentials: 'Telerik NuGet'

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

    - task: ArchiveFiles@2
      displayName: 'Archive Function'
      #condition: and(succeeded(), eq(variables.isDeployableBranch, true))
      inputs:
        rootFolderOrFile: '$(System.DefaultWorkingDirectory)/src/FunctionApp'
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/FunctionApp.zip'
        replaceExistingArchive: true

    - task: PublishBuildArtifacts@1
      condition: and(succeeded(), eq(variables.isDeployableBranch, true))
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'


- stage: Deploy
  displayName: Deploy
  condition: and(succeeded(), eq(variables.isDeployableBranch, true))
  jobs:  
  - deployment: DeployFunction
    displayName: Deploy Function
    environment: 'PROD'
    strategy:
      runOnce:
        deploy:
          steps:
          - checkout: none
          - task: DownloadBuildArtifacts@0
            inputs:
              buildType: 'current'
              downloadType: 'single'
              artifactName: 'drop'
              downloadPath: '$(System.ArtifactsDirectory)'

          - task: AzureFunctionApp@1 
            inputs:
               azureSubscription: 'MyResourceGroup'
               appType: functionApp
               appName: 'MyFunction'
               package: '$(System.ArtifactsDirectory)/**/FunctionApp.zip'

I think something is wrong before Archive stage. For other regular mvc apps targeting .net framework, the same pipeline works fine but for the azure function. Am I missing something?

This is my function's structure:

在此处输入图像描述

And the below YAML works fine:

steps:
- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.4.1'
  inputs:
    versionSpec: 4.4.1

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(Parameters.solution)'

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '$(Parameters.solution)'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

- task: ArchiveFiles@2
  displayName: 'Archive $(System.DefaultWorkingDirectory)\FrameworkFunction\bin\release\net48\*'
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)\FrameworkFunction\bin\release\net48\*'

- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy: testbowman0613'
  inputs:
    azureSubscription: 'testbowman_in_AAD'
    appType: functionApp
    appName: testbowman0613
    package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'

在此处输入图像描述

The key is the path must be correct, otherwise, it will not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM