Azure pipeline for Azure Function does not find project - azure-devops

I've got a build pipe for an Azure Function using .Net Core 3.1.x. All the steps until the publishing are doing fine. I can get the publish step working by using script, but not through the yaml task. What am I missing?
Script (works)
- script: dotnet publish --configuration Release .\af-process-mds-vehicle-output-to-deviation\af-process-mds-vehicle-output-to-deviation.csproj
Task (does not work)
- task: DotNetCoreCLI#2
displayName: 'Publish Project'
inputs:
command: 'publish'
configuration: 'Release'
projects: '.\af-process-mds-vehicle-output-to-deviation\af-process-mds-vehicle-output-to-deviation.csproj'
zipAfterPublish: true
It doesn't find the project.
Here's the error message.
2021-10-29T05:21:44.3024816Z ##[section]Starting: dotnet publish
2021-10-29T05:21:44.3150367Z ==============================================================================
2021-10-29T05:21:44.3150726Z Task : .NET Core
2021-10-29T05:21:44.3151190Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2021-10-29T05:21:44.3151475Z Version : 2.187.0
2021-10-29T05:21:44.3151733Z Author : Microsoft Corporation
2021-10-29T05:21:44.3152035Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2021-10-29T05:21:44.3152373Z ==============================================================================
2021-10-29T05:21:44.7797987Z [command]C:\Windows\system32\chcp.com 65001
2021-10-29T05:21:44.7903026Z Active code page: 65001
2021-10-29T05:21:44.7927221Z 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.
2021-10-29T05:21:44.8938257Z ##[error]No web project was found in the repository. Web projects are identified by presence of either a web.config file, wwwroot folder in the directory, or by the usage of Microsoft.Net.Web.Sdk in your project file. You can set Publish web projects property to false (publishWebProjects: false in yml) if your project doesn't follow this convention or if you want to publish projects other than web projects.
2021-10-29T05:21:44.9001249Z 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://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2021-10-29T05:21:44.9003648Z ##[error]Project file(s) matching the specified pattern were not found.
2021-10-29T05:21:44.9182124Z ##[section]Finishing: dotnet publish
After the tips from the answer I got the pipe working. Here's the full working pipe. (Still don't know why it didn't work earlier.)
Working pipe:
name : af-vehicle-sync-to-deviation
## if there is a change is the deviation folder for the main branch. Then trigger.
trigger:
branches:
include:
- main
paths:
include:
- af-process-mds-vehicle-output-to-deviation/*
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
SolutionPath: '**\*.sln'
stages:
- stage: Build
displayName: Build solution
jobs:
- job: Build
displayName: Build and publish solution
steps:
- checkout: self
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: $(SolutionPath)
- task: UseDotNet#2
inputs:
packageType: 'sdk'
version: '3.1.x'
displayName: 'Use .NET Core SDK 3.1.x'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
configuration: $(buildConfiguration)
projects: '$(SolutionPath)'
displayName: 'Build solution'
- task: DotNetCoreCLI#2
displayName: 'Publish Project'
inputs:
command: 'publish'
configuration: 'Release'
projects: '**\*.csproj'
publishWebProjects: false
zipAfterPublish: true
arguments: '--output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'

You could use '**/*.csproj' but honestly, I would do something like this answer and add a script to list out all the files and folders recursively before this step that fails.
Assuming that you have a restore or build step before this publish you could add it after those, or just as the first step after your checkout one.
You can also inspect the logs of earlier steps to see the file path/s., instructions on doing this are available here.
Using $(System.DefaultWorkingDirectory) as your root is also recommended, rather than .\, so you would have '$(System.DefaultWorkingDirectory)\af-process-mds-vehicle-output-to-deviation...'.
Edit
If you look at the logs for your build step you will see entries like /home/vsts/work/1/s/XXX.YYY.ZZZ/XXX.YYY.ZZZ.csproj that refer to the different projects inside your solution. By default most commands will be run in $(System.DefaultWorkingDirectory) which would equate to /home/vsts/work/1/s/ in this instance, you can think of it as the root of your repository - there is more information on this structure here.
The error you were encountering is actually about the lack of a web project, rather than a path issue though, for the build step it is best practice to use the --output <output-directory-here> flag to output the compile files into a specific folder, that way you can easily publish that folder.

Related

Devops build pipeline yaml - The current .NET SDK does not support targeting .NET Standard 2.0

Currently we are using (git) Bitbucket as source control, and Bamboo for build and deployment.
One of our projects is a legacy .NET Framework 4.7.2 MVC application. Some projects in that solution were once migrated to netstandard2.0. So the main MVC project is .NET Framework 4.7.2, and all the others projects in the solution are either also .NET Framework 4.7.2, or netstandard2.0.
Visual Studio (2019) has no problems building and running the entire solution. And Bamboo has no problems building and deploying the solution as well. Bamboo builds with MSBuild.
But when I use the same MSBuild configuration in Azure DevOps, then I get build errors. I guess because of the mix of .NET SDK versions in the project.
My azure-pipelines.yml looks like this:
trigger:
- master
pool:
# also tried VS2019, but got same errors during build
vmImage: 'VS2017-Win2016'
variables:
solution: 'WebSolution.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:Configuration=web-develop /p:DeployOnBuild=false /p:PublishProfile=web.pubxml /p:AllowUntrustedCertificate=True'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
But why on Azure DevOps is it complaining about the mix of the SDK frameworks? Why is Visual Studio and Bamboo able to build the solution without any issue?
A compatible SDK version for global.json version: [2.0.2] from [D:\a\1\s\global.json] was not found
##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(126,5): Error : The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0.
Project "D:\a\1\s\WebSolution.Bc.Common\WebSolution.Bc.Common.csproj" (2) is building "D:\a\1\s\Web.WebData\Web.WebData.csproj" (4:2) on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(126,5): error : The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0. [D:\a\1\s\Web.WebData\Web.WebData.csproj]
Is there a way to fix this in DevOps without having migrate every project in the solution to .NET Core?
I was facing a similar issue mixing .net standard 2.1 and dotnet 6 in a test pipeline. I didn't even get an error in the inital test pipeline... it just failed like... "Hey I could execute everything, but I doubt you want me to succeed".
Anyway... it turned out to be the nuget package manager, which was complaining that some of the nugets in the solution are not compatible with every project in the solution
Heres what i did to fix it:
trigger:
- master
pool:
vmImage: windows-latest
steps:
#specify the nuget tool
- task: NuGetToolInstaller#0
inputs:
versionSpec: '5.x'
displayName: 'Use latest NuGet 5'
#restore the nuget packages manually
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
noCache: true
displayName: 'Restore NuGet Packages'
#specify the dotnet sdk manually
- task: UseDotNet#2
inputs:
packageType: 'sdk'
version: '6.x'
displayName: 'Use latest dotnet 6'
#start your actual pipeline
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '**/*.csproj'
displayName: 'Build Solution'
- task: DotNetCoreCLI#2
inputs:
command: 'test'
testRunTitle: 'Testing'
projects: '**/*.csproj'
displayName: 'Executing Unittests'
I know its been a long time but i still hope this helps someone out there.

Build Pipeline keep crashing at Publish level of Azure Functions

I am trying to build and deploy an Azure Function using Devops Pipeline (CI)
These are my steps
But everything till step Publish executing without any error. But at the Publish level I am getting this error (As in the image above)
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://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.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: Publish
I thought its because of .Net version thats why I have added Use .NET 5.x step just before publish. But it still triggering the same error.
Here is the Yaml of these 3 steps
steps:
- task: DotNetCoreCLI#2 displayName: 'dotnet build' inputs:
projects: 'Toolset/ScheduledJobs/*.csproj'
steps:
- task: UseDotNet#2 displayName: 'Use .NET Core sdk 5.x' inputs:
version: 5.x
steps:
- task: DotNetCoreCLI#2 displayName: Publish inputs:
command: publish
publishWebProjects: false
projects: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingdirectory)/ScheduledJobs'
zipAfterPublish: false
modifyOutputPath: false
Please let me know what I did wrong there?
I developed the Azure Function (3.0) in VS 2019
When you publish you need provide path to the project like here:
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
projects: 'BlazorSample.csproj'
arguments: '--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)"'
zipAfterPublish: false
workingDirectory: $(Build.SourcesDirectory)/stackoverflow/51-blazor-sample/BlazorSample
Please notice working directory at the end.
Also change your order bu putting
- task: UseDotNet#2 displayName: 'Use .NET Core sdk 5.x' inputs:
version: 5.x
before this:
- task: DotNetCoreCLI#2 displayName: 'dotnet build' inputs:
projects: 'Toolset/ScheduledJobs/*.csproj'

Error deploying a folder artifact to Azure app service

I'm using Azure Dev Ops to run my build and release pipelines. I've got a build script that publishes my web code to an artifact folder (using .NET SDK projects), and I just need to push this code into my Azure app service. I've tried the "Azure app service deploy" and "Deploy code to app service" tasks in the release pipeline, giving it the publish settings file from my Azure instance and pointing to the folder with my code (since it says it takes zip or folder). On the console at this step, however, I get an error message of "No such deploying method exists."
I was able to get things pushed through FTP but I'd like to understand why the app service publish didn't work, as there are options (like deployment slots) that might be needed in the future. Is this a scenario where using the Azure resource manager connection would work better? Or does my build artifact need to be zipped after all? If it has to be zipped as a web deploy, is there a step to do this after a solution build, because I have to copy files into the artifact folder for transforms first, so I can't just do a comprehensive web build/zip.
I don't see details of your pipeline so I would share mine. I'm deploying zip package:
In Package or folder dialog I have:
I use YAML in my pipelines but it is easy to understand and follow if you want to have similar in classic pipelines:
trigger: none
pr: none
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
projectDirectory: 'app-service-deployment-to-slot-with-preview\hadar'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
workingDirectory: $(projectDirectory)
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: false
projects: '$(projectDirectory)\hadar.csproj'
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- task: CopyFiles#2
displayName: 'Copy configuration settings checks'
inputs:
contents: app-service-deployment-to-slot-with-preview\scripts\**
targetFolder: '$(Build.ArtifactStagingDirectory)\scripts'
flattenFolders: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifacts'

Trying to publish a build to Nuget.org

I'm new to Azure DevOps; however, what I'm doing seems like it should be straightforward: I simply want to compile a project and publish to NuGet.org. I'm hitting that many barriers to doing it that I feel that I'm probably mis-using the tool.
I have a build which looks like this:
trigger:
- master
pool:
vmImage: 'windows-2019'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration) /property:Version=$(Build.BuildNumber)
displayName: 'dotnet build $(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
This successfully builds. However, I do get the following warning:
##[warning]Directory 'd:\a\1\a' is empty. Nothing will be added to build artifact 'drop'.
When I try to deploy, I'm getting errors - the latest of which is:
No files matched the search pattern.
In dotnet pack, here's the release step for pack:
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet pack'
inputs:
command: pack
packagesToPack: '$(System.DefaultWorkingDirectory)/name.project'
This is what's currently failing, but the next step is intended to publish to NuGet (for completeness - and incase there's an easier way to do all this):
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet pack'
inputs:
command: pack
packagesToPack: '$(System.DefaultWorkingDirectory)/name.project'
The release has an artifact, which I've set up as the output from the build (I think); however, I get the error from this:
No version is available for name.project or the latest version has
no artifacts to publish. Please check the source pipeline.
My understanding of how this should work in general is that the Build should hold the steps involved in producing the binaries, etc, whereas the Release should be any steps involved in deploying the built. So, I should be able to take a 'Build' and 'Release' it several times to multiple locations. I feel like this understanding is not in-keeping with the errors that I'm seeing.
Is my understanding correct?
What could I be doing wrong here and, more importantly, what are the methods of diagnosing issues with this?
Trying to publish a build to Nuget.org
For the first error, that because you are mising the Copy Files task before using the Publish Build Artifacts task.
Check the Publish Build Artifacts task, you can view this task is used to publish build artifacts to Azure Pipelines, TFS, or a file share.
But after build the project/solution, the output are stored on the build agent, rather than the artifacts. So we need to add a copy task before PublishBuildArtifacts to copy the files from output to the artifacts:
steps:
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
TargetFolder: '$(build.artifactstagingdirectory)'
enabled: false
For the second error, you should specify the project in the repos instead of System.DefaultWorkingDirectory, where is use to build the project, change the Path to csproj in the repos:
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet pack'
inputs:
command: pack
packagesToPack: NetCoreDemo/NetCoreDemo/NetCoreDemo.csproj
Hope this helps.
You man need to provide the --output argument for dotnet build. Add the following
--output $(Build.ArtifactStagingDirectory)
so the command should look something like this.
dotnet build --configuration $(buildConfiguration) /property:Version=$(Build.BuildNumber) --output $(Build.ArtifactStagingDirectory)
this will put the output into the Artifact Staging Directory (d:\a\1\a)
which will include the *.nupkg file.
I am assuming you are using the new CSProj format and you are supplying the properties for the NuGet package and have the <GeneratePackageOnBuild>true</GeneratePackageOnBuild> property already set. If so the *.nupkg file should be in the output directory that you define in the dotnet build command. Then you don't need to use dotnet pack. In the release definition you just need to use the NuGet task and use push command to push the package to your NuGet Feed.
Use this blog post as reference. It does not have the full details since its focusing only on few aspects of the entire process. but it should be helpful to get the build aspect correct.

##[error]Project file(s) matching the specified pattern were not found

I am having problems with a build pipeline.
The agent pools is hosted VS2017
The YAML is
pool:
vmImage: 'VS2017-Win2016'
variables:
buildConfiguration: 'Debug'
steps:
- task: DotNetCoreInstaller#0
displayName: 'Use .NET Core sdk 2.1.5'
inputs:
version: 2.1.403
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: '**/Api*.csproj'
#Your build pipeline references an undefined variable named ‘Parameters.projects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.projects)'
arguments: '--configuration $(BuildConfiguration)'
#Your build pipeline references an undefined variable named ‘Parameters.projects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: false
projects: '$(Parameters.projects)'
arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
When it runs, the build task has the following log
2018-10-29T18:28:43.7087338Z ##[section]Starting: Build
2018-10-29T18:28:43.7093502Z ==============================================================================
2018-10-29T18:28:43.7093580Z Task : .NET Core
2018-10-29T18:28:43.7093785Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
2018-10-29T18:28:43.7093818Z Version : 2.141.0
2018-10-29T18:28:43.7093864Z Author : Microsoft Corporation
2018-10-29T18:28:43.7093895Z Help : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
2018-10-29T18:28:43.7093925Z ==============================================================================
2018-10-29T18:28:44.4833128Z [command]C:\Windows\system32\chcp.com 65001
2018-10-29T18:28:44.4926077Z Active code page: 65001
2018-10-29T18:28:45.1965225Z ##[error]Project file(s) matching the specified pattern were not found.
2018-10-29T18:28:45.2037015Z ##[section]Finishing: Build
I note that the log refers to 2.141.0 where as I am restoring the latest SDK 2.1.403 Why would that be? Could it be that the hosted VS2017 agent does not support the latest version of .netcore?
[Update]
I added a variable for Parameters.projects
However the build task has an error still.
2018-10-29T21:07:38.6774331Z ##[section]Starting: Build
2018-10-29T21:07:38.6781540Z ==============================================================================
2018-10-29T21:07:38.6781632Z Task : .NET Core
2018-10-29T21:07:38.6781676Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
2018-10-29T21:07:38.6781762Z Version : 2.141.0
2018-10-29T21:07:38.6781807Z Author : Microsoft Corporation
2018-10-29T21:07:38.6781853Z Help : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
2018-10-29T21:07:38.6781915Z ==============================================================================
2018-10-29T21:07:39.5030735Z [command]C:\Windows\system32\chcp.com 65001
2018-10-29T21:07:39.5157531Z Active code page: 65001
2018-10-29T21:07:39.5840366Z ##[error]Project file(s) matching the specified pattern were not found.
2018-10-29T21:07:39.5916864Z ##[section]Finishing: Build
Posting just in case this helps anyone in the future
I had my vmImage set as ubuntu with the following set:
projects: '**\*.csproj'
The backslash was throwing things off, I had to switch to the following:
projects: '**/*.csproj'
I copied from a guide that was assuming Windows. Subtle enough, it took me a while to notice 😅
You need to define in the build task which .csproj files you want to build.
In your case, the definition is in a variable $(Parameters.projects).
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.projects)'
arguments: '--configuration $(BuildConfiguration)'
You can replace this variable in your .csproj (e.g. **/*.csproj for all .csproj files in all subfolders):
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '**/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
Or go to the variables tab and add the Parameters.projects variable:
I am trying to build and publish a multiproject solution in dotnet core.
The solution structure is:
sampleTest.API
sampleTest.API.csproj
sampleTest.Data
sampleTest.Data.csproj
sampleTest.Identity
sampleTest.Identity.csproj
sampleTest.Web
sampleTest.Web.csproj
sampleTest.sln
Now, I just want to build the sampleTest.API dotnet core project. I just need to define in the build task, the path to the project as shown below.
The yaml file for build task for the pipeline in Azure Deveops is shown below:
steps:
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: 'sampleTest.API/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
If we need to build based on searching for all the 'cs.proj' files - we do
projects: '**/*.csproj'
Sample build task using the classic Editor in Azure Devops is shown below: