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'
Related
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.
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.
Following this code:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-azure-devops?tabs=csharp%2Cwindows
the Build pipeline fail on the "script" task with this error
enter image description here
If I replace this:
- task: DotNetCoreCLI#2
inputs:
command: publish
arguments: '--configuration Release --output publish_output'
projects: '*.csproj'
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
with this:
task: VSBuild#1
inputs:
solution: '***.sln'
msbuildArgs: '/p:OutDir=$(System.DefaultWorkingDirectory)/publish_output'
the build work but I need to publish
The project is built with Visual studio 2019 template for azure function. I did add an extra project to separate the logic, but it's all core 3.1. any suggestions?
According to your screen shot :( the build is using .NET Core 2.2.401, which has already reached end of life and is not .NET Core 3.1 as you expect.
You need to add a UseDotNet task to install the required .NET core release. Recommendation is that you have a global.json file for the version you expect.
- task: UseDotNet#2
displayName: 'Use .NET Core SDK (global.json)'
inputs:
packageType: 'sdk'
useGlobalJson: true
For useGlobalJson: false you can specifiy the version which should be used explicitly.
Is it possible to run a pre-release version of the DotNetCoreCLI task when writing an Azure Pipelines yaml script? I would like to use 3.0.1xx if possible to take advantage of dotnet tool update installing the tool rather than throwing an error if not installed.
If it is possible, what would the syntax be to make a call like this use a prerelease version rather than version 2:
- task: DotNetCoreCLI#2
continueOnError: true
inputs:
command: custom
custom: tool
arguments: install -g coverlet.console
displayName: Install Coverlet tool. This task will continue on error if coverlet is already installed.
you could use the following:
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk'
inputs:
packageType: sdk
version: 3.0.101
installationPath: $(Agent.ToolsDirectory)/dotnet
possible versions: https://github.com/dotnet/core/blob/master/release-notes/releases-index.json
reading: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/dotnet-core-tool-installer?view=azure-devops
I am having an issue with Azure Pipelines. I am trying to build an ASP.NET Core 3.0 project. Yes, I know it's not supported yet, but other questions say you can do it by including the following in the pipeline script. I am not sure how to do that, however.
task: DotNetCoreInstaller#0
displayName: 'Install .net core 3.0 (preview)'
inputs: version: '3.0.100-preview6-012264'
Do I paste the above in the following script? If not, where would I place it? Also, I am on Preview 9 at present—is that supported yet?
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
Do I paste the following in the below script or where would i place it
You can paste following scripts at begin of Steps, like:
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk 3.0.100-preview9-014004'
inputs:
version: '3.0.100-preview9-014004'
includePreviewVersions: true
- task: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
...
You can get it by searching use .net core in the search box:
I am on preview 9 at present does that support it yet
The answer is yes. This task is used to install the .NET SDK, which supports the .NET core 3.0 preview versions list.
As test result:
Hope this helps.
You probably want to use the UseDotNet#2 task. You can add it to your list of steps.
Here's an example...
- steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk'
inputs:
packageType: sdk
version: 3.x
includePreviewVersions: true
installationPath: $(Agent.ToolsDirectory)/dotnet
- script: ... etc etc
displayName: Continue as normal, now that the .net core 3.x SDK is installed.
And yes, preview9 is supported. So is rc1. This step installs the latest 3.x version and includes all previews. Once it's released, you can remove the includePreviewVersions field if you want.
For more info, the docs are here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/dotnet-core-tool-installer?view=azure-devops