简体   繁体   English

无法部署面向 .net 框架 4.8 的 azure 功能

[英]Unable to deploy azure function targeting .net framework 4.8

I have a Azure function that is targeting .net framework 4.8我有一个面向 .net framework 4.8 的 Azure 函数

It's working fine when I deploy it thorough visual studio but I am trying to create a azure-pipeline.yml file for deployment.当我通过 Visual Studio 部署它时它工作正常,但我正在尝试创建一个用于部署的 azure-pipeline.yml 文件。 But it actually put the root level files in the artifact folder and not the ones that visual studio puts in the publish folder.但它实际上将根级文件放在工件文件夹中,而不是 Visual Studio 放在发布文件夹中的文件。

I can't find any good help for .net framework.我找不到 .net 框架的任何好的帮助。

Here is my yaml file:这是我的 yaml 文件:

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.对于其他针对 .net 框架的常规 mvc 应用程序,相同的管道可以正常工作,但适用于 azure 函数。 Am I missing something?我错过了什么吗?

This is my function's structure:这是我函数的结构:

在此处输入图像描述

And the below YAML works fine:下面的 YAML 工作正常:

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.关键是路径必须正确,否则将无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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