'Publish ASP.NET Core Web API to on premise servers

I'm trying to publish an ASP.NET Core Web API to an on premise server from Azure Devops.

I've successfully installed the agent on the target machine. I've succesfully created the build pipeline.

Here is the yaml file:

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- Version_1.0.26_In_Prod_HotHix_master

pool:
  vmImage: 'windows-latest'

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

steps:
- task: NuGetAuthenticate@0
  inputs:
    nuGetServiceConnections: 'Nuget feed RTE (Sleet)'
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'
    feedsToUse: 'config'
    nugetConfigPath: 'NuGet.config'
    externalFeedCredentials: 'Nuget feed RTE (Sleet)'

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

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

I've created a release pipeline and linked an artifact. When I run this, it fails with the following error:

Error: No package found with specified pattern.
Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.

Am I missing something about the package location while a build is selected when I'm creating the release pipeline ?



Solution 1:[1]

I think you need to publish your artifact in your build pipeline. Example:

- task: PublishPipelineArtifact@1
  displayName: 'Publish Pipeline Artifact'
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)'
    artifact: drop

Solution 2:[2]

The solution was to add the CopyFiles@2 inspired from here.

- task: CopyFiles@2
  inputs:
       SourceFolder: '$(system.defaultworkingdirectory)'
       Contents: '**\bin\$(BuildConfiguration)\**'
       TargetFolder: '$(build.artifactstagingdirectory)'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shamrai Aleksander
Solution 2 Olivier MATROT