I have a .net core 3.0 azure function project in an existing solution. While it builds and runs fine in visual studio, the CDPX for it sometimes failed with message-
MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1
The YAML being used-
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet core test'
inputs:
command: test
projects: '**\*ProjectDllName.dll'
Running the same build again fixes the issue. But this is happening very frequently now.
Related
I'm trying to test my .NET Core 5.0 projects in my Azure DevOps pipeline. When using a full path to one of my test projects the pipeline will test that single project. When using a pattern to search for all my test projects he can't find one of them.
My project structure is as follows:
backend
DemoProject (with the .sln file)
DemoProject.Application
DemoProject.Application.Test
DemoProject.Persistance
DemoProject.Persistance.Test
DemoProject 2
....
To find a solution I created a simple version of my pipeline template:
- master
pool:
vmImage: ubuntu-latest
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: './backend/DemoProject/DemoProject.Application.Tests/DemoProject.Application.Tests.csproj'
When using the full path (./backend/DemoProject/DemoProject.Application.Tests/DemoProject.Application.Tests.csproj), the pipeline find's the selected project. When using a pattern (./backend/DemoProject/\*\*/\*.Tests.csproj or ./backend/DemoProject/\*\*/DemoProject.Application.Tests.csproj), the pipeline can't find any project.
Does someone knows what the correct pattern is to run all my test projects inside the DemoProject folder?
Try **/*.Test.csproj, I have used it in projects with more complex folder structures without any issues.
- task: DotNetCoreCLI#2
inputs:
command: test
arguments: --configuration Release
projects: '**/*.Test.csproj'
workingDirectory: './backend/DemoProject/'
I'm trying to build and pack a class library into a NuGet using .NET Core 3.1. It all build fine on my dev machine, but the Azure pipeline build fails during the DotNetCoreCLI pack command. I was able to get the build working on after installing .NET Core 3.1 on the build machine using the UseDotNet. Build and tests run fine, so I believe the 3.1 version is installed correctly.
When I add the pack command, the step always fails. Here is the command I'm using:
- task: DotNetCoreCLI#2
displayName: Package NuGet
inputs:
command: 'pack'
projects: '**/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
outputDir: '$(Build.ArtifactStagingDirectory)/packages'
I get the following error during this step:
/opt/hostedtoolcache/dotnet/sdk/3.1.101/Sdks/NuGet.Build.Tasks.Pack/build/NuGet.Build.Tasks.Pack.targets(198,5):
error NU5026: The file
'/home/vsts/work/1/s/ClassLib31/bin/Debug/netcoreapp3.1/ClassLib31.dll'
to be packed was not found on disk.
[/home/vsts/work/1/s/ClassLib31/ClassLib31.csproj]
Notice the path above is looking bin Debug folder, but this is a Release build. All of the tasks are using the same BuildConfiguration variable, but in this task it appears to be looking for the dll in the Debug folder. Any ideas why?
Additional notes:
- This build script works fine for .NET Core 3.0 projects. I tried switching the library to target 3.0 and removed the 3.1 installation step. Pack works as expected.
- This build script works when I build the Debug version of the library (as you'd expect, since the task is looking in that bin folder).
DotNetCoreCLI#2 Pack command does not support arguments argument.
Arguments to the selected command. For example, build configuration,
output folder, runtime. The arguments depend on the command selected
Note: This input only currently accepts arguments for build, publish,
run, test, custom. If you would like to add arguments for a command
not listed, use custom.
You may use arguments argument for build command and configuration argument for pack command:
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: 'build'
arguments: '--configuration Release'
...
- task: DotNetCoreCLI#2
displayName: Pack
inputs:
command: 'pack'
configuration: 'Release'
...
There is another workaround, but note that in this case packagesToPack argument does not work:
# command: 'pack'
command: custom
custom: pack
arguments: '--configuration Release'
After a little more time debugging the build pipeline, I discovered that I had mismatched case the BuildConfiguration variable in a couple of places, which caused this to fail in the pack command. I discovered this while combing through the logs for each step.
It seems that if the case mismatch is in earlier commands (like build and test) they default to the release build. But for the pack command it seems to default to look in the debug bin folder. Once I discovered this and cleaned up the script, it works fine now .NET Core 3.1 builds.
I have a repository which has nothing on master, except the Readme and azure-pipelines.yml YAML. On the development branch (the branch I want to build and deploy and have CI on) there are three folders, MVC, Test, and Console, each containing a project (an MVC version of an ASP.NET Core MVC, .NET Core console, and Xunit test project). I want to run dotnet restore and build on the MVC project, but I get the error:
2019-02-08T15:09:20.9373945Z ##[section]Starting: CmdLine
2019-02-08T15:09:20.9468192Z ==============================================================================
2019-02-08T15:09:20.9468291Z Task : Command Line
2019-02-08T15:09:20.9468353Z Description : Run a command line script using cmd.exe on Windows and bash on macOS and Linux.
2019-02-08T15:09:20.9468441Z Version : 2.146.1
2019-02-08T15:09:20.9468490Z Author : Microsoft Corporation
2019-02-08T15:09:20.9468565Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
2019-02-08T15:09:20.9468629Z ==============================================================================
2019-02-08T15:09:22.4499876Z Generating script.
2019-02-08T15:09:22.5206191Z ##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\21484123-df40-47c7-9383-7f526daaa124.cmd""
2019-02-08T15:09:22.8173263Z MSBUILD : error MSB1009: Project file does not exist.
2019-02-08T15:09:22.8173430Z Switch: MVC
2019-02-08T15:09:23.1247189Z Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
2019-02-08T15:09:23.1308513Z Copyright (C) Microsoft Corporation. All rights reserved.
2019-02-08T15:09:23.1308642Z
2019-02-08T15:09:23.1308714Z MSBUILD : error MSB1009: Project file does not exist.
2019-02-08T15:09:23.1308801Z Switch: MVC
2019-02-08T15:09:23.2993350Z ##[error]Cmd.exe exited with code '1'.
2019-02-08T15:09:23.3158684Z ##[section]Finishing: CmdLine
The YAML file in master is the following:
# 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:
- dev
- master
pool:
vmImage: 'vs2017-win2016'
#- task: DotNetCoreInstaller#0
# inputs:
# version: '2.2.103' # replace this value with the version that you need for your project
steps:
- script: |
dotnet restore MVC
dotnet build MVC
- task: PublishBuildArtifacts#1
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- task: PublishBuildArtifacts#1
Is there a way to access MVC for the dotnet commands?
I am trying to add Code Coverage results in an Azure DevOps build for a .NET Core project, but, trying two different approaches based on this guide on MSDN:
Currently, after building the solution, I have a dotnet step for test, collecting the Code Coverage and publishing those results. I also tryed disabling this check for publishg, and adding a command line step and a Publish Test Results.
Here the screenshot and yaml for the test step:
- task: DotNetCoreCLI#2
displayName: 'Test solution'
inputs:
command: test
projects: '**/*Test/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
workingDirectory: ChustaSoft.Common.UnitTest
And here the screenshots and yaml for the currently disabled steps:
- script: 'dotnet test ChustaSoft.Common.UnitTest --logger trx --collect "Code coverage"'
displayName: 'Command Line Script'
enabled: false
- task: PublishTestResults#2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: VSTest
testResultsFiles: '**/*.trx'
enabled: false
With both approaches, I could see Test results, but not the Code Coverage, here is an screenshot of what I am able to see it:
Any idea? I am missing something? How can I see the Code Coverage when the build is finished?
Thank you a lot in advance,
PD: Project is multitarget: .NET Core 2.0, .NET Standard 2.0 and .NET 4.6.1, UnitTest project is a .NET Core MSTest project
EDIT: Added Test step output:
Try to run the tests with adding first
Visual Studio Test Platform Installer Task
then
Visual Studio Test -->>Test assemblies Task
Remove the Publish Test and the Command line Tasks.
I am having trouble configuring an Azure DevOps Dotnet core build process.
I have a simple dotnet core project which I am attempting to build in an Azure DevOps environment.
The project is in a subfolder within my repo, but I cannot figure out how to specify how the Pipeline should find my csproj file. The MSDN documentation suggests that you can specify it but there are no examples and all of my attempts are met with errors.
When building a pipeline with the standard dotnet CLI template, the YAML created is:
# ASP.NET Core
# Build and test ASP.NET Core web applications targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/vsts/pipelines/languages/dotnet-core
pool:
vmImage: 'Ubuntu 16.04'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
However this is met with the error:
MSBUILD : error MSB1003: Specify a project or solution file.
The current working directory does not contain a project or solution file.
The documentation linked above suggests using a "task" based syntax rather than a script, and I assume that in the documentation the inputs are listed in the same order as the examples listed underneath.
If you use the script you specify the csproj file after the build word:
- script: dotnet build myrepo/test/test.csproj --configuration $(buildConfiguration)
The best way to use Azure DevOps Pipeline is to use tasks for the build pipeline, in the Dotnet Core yaml build task you specify the file in the inputs section:
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: 'myrepo/test/test.csproj'