Azure Pipeline dotnet push error finding nuget package - .net-core

My code for the azure pipeline
I have Problems using the azure pipeline, which will automatically pack my libraries on azure devops git and push it as a nugetpackage to artifacts.
I get the error ##[error]No packages matched the search pattern.
at dotnet push
Until that step everything works. I want to pack it as a nuget so i can use it in other projects.
Its a API Client i wrote for my own API.

Try using the artifact path from artifact staging directory
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
projects: '**/*.csproj'
- task: DotNetCoreCLI#2
displayName: "dotnet pack"
inputs:
command: 'pack'
arguments: '--configuration $(buildConfiguration)'
packagesToPack: '**/*.csproj'
nobuild: true
versioningScheme: 'off'
- task: NuGetCommand#2
displayName: 'nuget push'
inputs:
command: 'push'
feedsToUse: 'select'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: '<Name of Your Feed>'
versioningScheme: 'off'
allowPackageConflicts: true
https://medium.com/#gstvribs/how-to-use-and-deploy-azure-devops-artifacts-on-azure-pipelines-with-dotnet-dockerized-8cebd724f752

Please add to dotnet pack for instance setting like this to your inputs:
packDirectory: "$(Build.ArtifactStagingDirectory)/packages"
And then to dotnet push setting like this:
packagesToPush: '$(Build.ArtifactStagingDirectory)/packages/*.*nupkg'
In your approach it simply try to find packages in defualt folder but you didn't put packages there.

Related

Azure Pipeline: Project file(s) matching the specified pattern were not found

this is my pipeline:
pool:
vmImage: windows-latest
steps:
- task: NuGetToolInstaller#1
displayName: 'Install NuGet >=6.3.0-0'
inputs:
versionSpec: '>=6.3.0-0'
checkLatest: true
- task: UseDotNet#2
displayName: Use DotNet Version 7.0.x
inputs:
version: '7.0.x'
includePreviewVersions: true # Required for preview versions
- task: NuGetCommand#2
displayName: 'Nuget Restore Packages'
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
vstsFeed: '11b33a23-a7bd-4e05-bce5-7383e054c4f4/3aef100d-2005-4893-9c82-65ed96a2b539'
- task: DotNetCoreCLI#2
displayName: 'Build Web API projects'
inputs:
command: build
projects: '**/*src/*.csproj'
arguments: '--configuration $(buildConfiguration)' # Update this to match your need
- task: DotNetCoreCLI#2
displayName: 'Build Database Migrator'
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/*tools/*DatabaseMigrator.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/App_Data/jobs/triggered -r win-x64 --self-contained false'
- task: DotNetCoreCLI#2
displayName: 'Build Frequently Operations'
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/*tools/*FrequentlyOperations.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/App_Data/jobs/continuous -r win-x64 --self-contained false'
- task: DotNetCoreCLI#2
displayName: 'Create Zip Build For Release'
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
# this code takes all the files in $(Build.ArtifactStagingDirectory) and uploads them as an artifact of your build.
- task: PublishPipelineArtifact#1
displayName: 'Publish Artifact(Zip File) For Release'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: 'output'
when it is triggered it shows this error:
Starting: Build Web API projects
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.210.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Project file(s) matching the specified pattern were not found.
Finishing: Build Web API projects
this is my project:
Any suggestions ?
##[error]Project file(s) matching the specified pattern were not found.
Reproduce the same issue when the csproj file is not in the root node of the src folder.
For example:
-- src
--projectname
-- xxx.csproj
-- projectname1
Usually the src folder will contain multiple project folders.
To solve this issue, you need to check the src folder structure and define the folder path of the dotnet task.
For example:
- task: DotNetCoreCLI#2
displayName: 'Build Web API projects'
inputs:
command: build
projects: '**/*src/** or subfolder name/*.csproj'
arguments: '--configuration $(buildConfiguration)'
From the screenshot of your repo, I didn't see a csproj in your project.
You need to have a csproj in your project.
You could also use sln to restore and build your project.
steps:
- task: UseDotNet#2
displayName: 'Install .NET Core SDK'
inputs:
version: 5.0.x
performMultiLevelLookup: true
includePreviewVersions: true # Required for preview versions
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '**/*.sln'
displayName: 'Restore Nuget Packages'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '**/*.sln'
arguments: '--no-restore'
displayName: 'Build projects'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration $(buildConfiguration) --output $(build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: 'api.chibebinam'

Visual Studio Build & Publish vs Azure Devops Pipeline Build and Release

I have a dotnet core project (API, not web) which is linked to an Azure Repo Git. We build the project within Visual Studio (professional 2022) and publish it to a folder locally.
I'm then taking that folder copy and pasting it under C:\inetpub\wwwroot\coinia-api-new\ in my Windows Server. This API is an IIS falling under default website. The API then works as expected and yields result when we hit it.
If I perform the same task using Azure Build Pipeline and then publish the artifact to the Windows server using Azure Release pipeline, at the same path (C:\inetpub\wwwroot\coinia-api-new), the build and release succeed but the API doesn't work and gives error 500.
I'm using a standard dotnet core build template for building the solution. I have also tried using MSBuild and VsBuild.
And standard IIS Deploy task for the deployment using release pipeline.
The builds succeed and reproduces the artifact but after deploying, the API still doesn't work.
Below is the yaml for build pipeline:
# Agent Queue 'Azure Pipelines' was used with unrecognized Agent Specification, vmImage property must be specified to determine image - https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml#software
variables:
- name: BuildParameters.RestoreBuildProjects
value: '**/COINIA.CORE.API.csproj'
- name: BuildParameters.TestProjects
value: ''
name: $(date:yyyyMMdd)$(rev:.r)
jobs:
- job: Job_1
displayName: Agent job 1
pool:
name: Azure Pipelines
steps:
- checkout: self
fetchDepth: 1
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: $(BuildParameters.RestoreBuildProjects)
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: $(BuildParameters.RestoreBuildProjects)
arguments: --configuration $(BuildConfiguration)
- task: VSBuild#1
displayName: Build solution COINIA.CORE.API/COINIA.CORE.API.csproj
enabled: False
inputs:
solution: COINIA.CORE.API/COINIA.CORE.API.csproj
- task: DotNetCoreCLI#2
displayName: Test
enabled: False
inputs:
command: test
projects: $(BuildParameters.TestProjects)
arguments: --configuration $(BuildConfiguration)
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: false
projects: $(BuildParameters.RestoreBuildProjects)
arguments: --configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)
zipAfterPublish: false
- task: PublishBuildArtifacts#1
displayName: Publish Artifact
condition: succeededOrFailed()
inputs:
PathtoPublish: $(build.artifactstagingdirectory)
TargetPath: '\\my\share\$(Build.DefinitionName)\$(Build.BuildNumber)'
...
And here is my release pipeline snippets:

Per-project output directory with dotnet build (Azure DevOps)

I have a .NET Core solution with two projects (proj1 and proj2). When I run a build in Azure DevOps, I use the DotNetCoreCLI#2 command like this:
- task: DotNetCoreCLI#2
displayName: 'Build output'
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--output $(System.DefaultWorkingDirectory)/publish_output'
As is, all the artifacts from both builds end up in the publish_output directory. What I'd like is for there to be a proj1 and proj2 subdirectory created under publish_output and the artifacts from the projects placed appropriately.
Is this possible? I could not find a "currently being build project name" variable to append to the output directory.
Thank you Simply Ged. Posting your suggestions as answer to help other community members.
Add modifyOutputPath as a input as below and check
Here is the code
# Publish projects to specified folder.
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/*.csproj'
arguments: '-o $(Build.ArtifactStagingDirectory)/Output'
zipAfterPublish: true
modifyOutputPath: true
Follow the Publish Projects for further instructions.

dotnet build, exclude only one dependency from build

Consider the following project structure:
MyProject.Api.a
MyProject.Api.b
MyProject.Data, referenced by a and b
I've set up a pipeline in Azure devOps that performs a restore, build and publish like this:
jobs:
- job: api-a
steps:
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: "MyProject.Api.a.csproj"
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: "MyProject.Api.a.csproj"
arguments: "--configuration $(buildConfiguration)"
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
projects: "MyProject.Api.a.csproj"
publishWebProjects: false
arguments: "--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/project-api-a-publish"
- task: PublishPipelineArtifact#1
displayName: Publish release Artifact
inputs:
targetPath: "$(Build.ArtifactStagingDirectory)/project-api-a-publish"
artifactName: "a-publish"
- job: api-b
steps:
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: "MyProject.Api.b.csproj"
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: "MyProject.Api.b.csproj"
arguments: "--configuration $(buildConfiguration)"
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
projects: "MyProject.Api.b.csproj"
publishWebProjects: false
arguments: "--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/project-api-b-publish"
- task: PublishPipelineArtifact#1
displayName: Publish release Artifact
inputs:
targetPath: "$(Build.ArtifactStagingDirectory)/project-api-b-publish"
artifactName: "b-publish"
problem is that MyProject.Data is not buildable from source, it needs an external tool to run first that generates some C# classes. Before this step, the project won't be able to build.
So I added this:
- task: DotNetCoreCLI#2
displayName: "Restore tools"
inputs:
workingDirectory: "MyProject.Data"
command: custom
custom: tool
arguments: restore --interactive --configfile ../NuGet.config
- task: DotNetCoreCLI#2
displayName: my-codegen-tool
inputs:
workingDirectory: "MyProject.Data"
command: custom
custom: tool
arguments: run my-codegen-tool
This all works, but the codegen tool needs to run on each API project job I'm running, making my build quite slow.
I was hoping there would be some way to only run the codegen tool once, and then all API projects could use the binaries from the data project where the files were generated?
Ideally, I would have to be able to prebuild the data project in a separate job, publish the dll's as an artifact, and then use those dll's in my subsequent API builds. I'm guessing this would be possible with dotnet build --no-dependencies, but that would implicate I need to build everything else separately as well, which is undesirable from a maintainability point of view.
You can try to combine multiple jobs into one job. First generate the required C # classes through the first two tasks, and then build with wildcards (e.g. **/*.csproj for all .csproj files in all subfolders) in the dotnet build task.
You can consider removing restore tasks, because dotnet restore is run implicitly in dotnet build.
This is stated here : You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To disable implicit restore, use the --no-restore option.
- job:
steps:
- task: DotNetCoreCLI#2
displayName: "Restore tools"
inputs:
workingDirectory: "MyProject.Data"
command: custom
custom: tool
arguments: restore --interactive --configfile ../NuGet.config
- task: DotNetCoreCLI#2
displayName: my-codegen-tool
inputs:
workingDirectory: "MyProject.Data"
command: custom
custom: tool
arguments: run my-codegen-tool
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: "**/*.csproj"
arguments: "--configuration $(buildConfiguration)"

AzureDevOps - Can't publish as single file

Edit: see end of the post for working yaml.
I'm trying to publish a .NET Core 3.1 Console App as single file however I can't seem to succeed through Azure Devops Pipelines:
Self-contained or not, the publish result is always a bunch of dll instead of just being my executable.
Publishing as single fine works just fine on my computer (publishing from VS or the .NET Core CLI with the params I've set in the yaml below)
Here's the yaml responsible for the build:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- feature/linux
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet#2
displayName: 'Use .Net Core sdk 3.1.x'
inputs:
version: 3.1.x
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: './Project/Project.csproj'
feedsToUse: config
nugetConfigPath: ./NuGet/NuGet.Config
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
projects: './Project/Project.csproj'
arguments: '-o $(build.artifactstagingdirectory) -r linux-x64 -c Release -f netcoreapp3.1 -p:PublishSingleFile=true -p:SelfContained=false'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
Solution:
I'm dumb, simply forgot the command part under dotnet publish.. the resulting command by default is build.
Note that you need to also specify
publishWebProjects: false
For a console project, see full working yaml:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- feature/linux
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/Project.csproj'
feedsToUse: config
nugetConfigPath: ./NuGet/NuGet.Config
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/Project.csproj'
modifyOutputPath: true
arguments: '-o $(build.artifactstagingdirectory) -r linux-x64 -c Release -f netcoreapp3.1 -p:PublishSingleFile=true -p:SelfContained=false'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
artifactName: 'drop'
PathtoPublish: '$(build.artifactstagingdirectory)'
Any help is welcome :)
It would be very weird the same commands to produce different results locally and on the remote server.
You use the same SDK, it does not make any sense. The problem is somewhere else in the pipeline. I would suggest the following solutions.
1) Try to explicitly state the which folder to publish when publishing build artifacts, it seems like it is trying to publish the linux-x64 folder (one folder up). Like:
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
artifactName: 'drop'
PathtoPublish: '$(build.artifactstagingdirectory)'
2) Try instead of PublishSingleFile to zipAfterPublish. Like:
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
modifyOutputPath: true
arguments: '--configuration $(BuildConfiguration) --output "$(build.artifactstagingdirectory)"'
zipAfterPublish: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
projects: './Project/Project.csproj'
artifactName: 'drop'
PathtoPublish: '$(build.artifactstagingdirectory)'
I hope it helps...
Updated Answer
You need to specify in the publish task the command like command: publish.
yaml worked for me is:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- feature/linux
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DotNetCoreCLI#2
displayName: 'Restore Nuget Packages'
inputs:
command: 'restore'
projects: './Project/Project.csproj'
feedsToUse: config
nugetConfigPath: ./NuGet/NuGet.Config
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: publish
modifyOutputPath: true
arguments: '--configuration Release --output "$(build.artifactstagingdirectory)"'
zipAfterPublish: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
artifactName: 'drop'
PathtoPublish: '$(build.artifactstagingdirectory)'
By adding the explicitly the publish command in the publish task I confirmed that a zip file created as an artifact.
I've tested your .yml file, the log showed dotnet build not dotnet publish. You could try the following code:
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
projects: '**/*.csproj'
arguments: '--configuration Release --output "$(build.artifactstagingdirectory)"'
modifyOutputPath: true
zipAfterPublish: true
Or
- task: DotNetCoreCLI#2
inputs:
command: 'custom'
projects: '**/*.csproj'
custom: 'publish'
arguments: '--configuration Release --output $(build.artifactstagingdirectory)'

Resources