steps:
- task: DotNetCoreCLI#2
displayName: dotnet build
inputs:
command: 'build'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2
displayName: dotnet test
inputs:
command: test
projects: 'Playtech.Neon.Privacy.TestPlaytech.Neon.Privacy.Test.csproj'
arguments: '--configuration $(buildConfiguration)'
I've noticed that the test step builds the solution again, which is stupid because
the solution has already been built by the build step so the tests should just use the bin directory that's already been made.
Can it do this? How?
Dotnet commands like test or pack build the project by default.
There are 2 solutions to this:
Include the --no-build argument:
-task: DotNetCoreCLI#2
displayName: dotnet test
inputs:
command: test
projects: 'Playtech.Neon.Privacy.TestPlaytech.Neon.Privacy.Test.csproj'
arguments: '--no-build --configuration $(buildConfiguration)'
You can execute the tests on the .dll created by the build like so:
- script: dotnet test Playtech.Neon.Privacy.TestPlaytech.Neon.Privacy.Test.dll
workingDirectory: '<Path_To_The_Build_Directory>'
displayName: Run Tests
You can probably do the same with the DotNetCoreCLI#2 Task but I did not test that.
But overall reading the documentation is always a good first step ;)
Related
in my pipeline build .yml I have buildConfiguration: "Release" and use it in the build command
task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: "**/*.csproj"
arguments: '--configuration $(buildConfiguration)
I got
6.0.101\Roslyn\Microsoft.CSharp.Core.targets(75,5): Warning MSB3052: The parameter to the compiler is invalid, '/define:$(BUILDCONFIGURATION)' will be ignored.
in NET 6.0 build. Any suggestions for fix this warning?
I resolved the above build issue by updating the pipeline
Resolve the build waring The parameter to the compiler is invalid, '/define:$(BUILDCONFIGURATION)' will be ignored in NET 6.0
Since you could not share the whole YAML file, to resolve this issue requires you to do more troubleshooting.
As a suggestion, you can try changing your variable to a specific value to test if the issue persists, just instead of $(buildConfiguration) to release:
- task: DotNetCoreCLI#2
displayName: 'Build'
inputs:
command: build
projects: Net6Test/Net6Test/Net6Test.csproj
arguments: '--configuration release'
As test, I have created a .NET 6 sample project, and build it with below YAML scripts, and it works fine:
pool:
name: xxxx
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI#2
displayName: 'Build'
inputs:
command: build
projects: Net6Test/Net6Test/Net6Test.csproj
arguments: '--configuration $(buildConfiguration)'
I have a repository with many solutions in it. I'd like to set up a build pipeline in Azure DevOps and build specific solution. I only need the "standard" steps as "restore packages, build, run unit tests, publish". However, the "publish" step gives me a headache.
The folder hierarchy for the repository looks like this:
src
- Solution1
- Project1
- Project2
- Project3
- Solution2
- Project4
- Project5
...
My goal would be to publish only the projects of e.g. Solution2 - so Project4 and Project5. Setting the value of workingDirectory to "src/Solution2" or "$(System.DefaultWorkingDirectory)/src/Solution2" don't work as I expected.
Here's the definition of the build step.
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
workingDirectory: src/Solution2
In the logs, I see
"C:\Program Files\dotnet\dotnet.exe" publish [path_to_agent]_work\1\s\src\Solution1\Project1\Project1.csproj --configuration Release --output [path_to_agent]_work\1\a\Project1
and similar entries for every single project in the repository.
As a workaround I tried using the "custom" command, but it didn't work out either.
- task: DotNetCoreCLI#2
displayName: 'Publish'
inputs:
command: custom
arguments: 'src/Solution2 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) '
custom: publish
This produces a log entry as
"C:\Program Files\dotnet\dotnet.exe" publish [path_to_agent]_work\1\s\src\Solution1\Project1\Project1.csproj src/Solution2 --configuration Release --output [path_to_agent]_work\1\a\Project1
and eventually the pipeline fails as Only one project can be specified.
Any ideas what I'm doing wrong?
I had the same problem. After a lot of trials and errors I came to the conclusion that the workingdirectory parameter is just ignored as explained here.
Also I noticed globbing (**/*) does not work if you use quotes. Also publishWebProjects has to be set to false otherwise it will start searching for other projects from the default working folder.
So this worked for me:
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: false
configuration: $(buildConfiguration)
projects: |
$(System.DefaultWorkingDirectory)/pathToProjectA/projectA.csproj
$(System.DefaultWorkingDirectory)/pathToProjectB/*.csproj
You can try to use projects settings with globbing to get all csproj's:
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: 'publish'
publishWebProjects: false
projects: 'src/Solution2/**/*.csproj'
arguments: '-o $(Build.ArtifactStagingDirectory)/Output'
zipAfterPublish: true
modifyOutputPath: true
ALM on Azure DevOps 2019
Projet in .NET 5
langage C#
Issue on task 5
My goal is to exclude an integration test which is mixed with unit tests, and which therefore fails my pipeline
on local the dotnet test --filter FullyQualifiedName!=myProjet /p:CollectCoverage=true --configuration Release work well, but not in my pipeline
a have this:
I install yet .NET 5 in a previous task, but nothing to do it does not want to recognize my filter arguments, configuration.
pool:
vmImage: windows-latest
stages:
- stage: Build
jobs:
- job: Build
displayName: Build
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk'
inputs:
packageType: sdk
version: 5.x
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: DotNetCoreCLI#2
displayName: Restore dependencies
inputs:
command: restore
projects: "**/*.csproj"
arguments: --configfile nuget.config -v detailed
feedsToUse: select
vstsFeed: $(ARTIFACTS_FEED_NAME)
includeNuGetOrg: false
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: "**/*.sln"
workingDirectory: $(System.DefaultWorkingDirectory)
arguments: --no-restore --configuration $(BUILD_CONFIGURATION) --output $(Build.ArtifactStagingDirectory)/$(BUILD_CONFIGURATION)"
zipAfterPublish: false
modifyOutputPath: true
- task: CmdLine#2
displayName: Coverage
inputs:
script: "dotnet test \n--filter FullyQualifiedName!=wkf.WorkflowInvestorNotices.Test.Service.FileImportTest.GivenCompareExcelFileWhenReadCellsThenReturnResults\n--no-restore\n--configuration $(BUILD_CONFIGURATION)\n/p:CollectCoverage=true\n"
workingDirectory: $(System.DefaultWorkingDirectory)/wkf.WorkflowInvestorNotices
Do you have any idea for my pipeline to recognize these arguments?
Dotnet test '--filter' is not recognized on Azure DevOps
You could use --filter with the dotnet test task instead of the command line task:
For the issue in your comment, you do not get the code cover board. Please check if you enable the option Publish test results and code coverage in that task.
If that not help you, please share the build log in your question.
I have the following task in an Azure DevOps pipeline:
- task: DotNetCoreCLI#2
inputs:
command: test
projects: '**/tests/*/*.csproj'
arguments: '--configuration $(buildConfiguration)'
displayName: 'dotnet test'
pretty simple stuff.
Is there a way I can just list the projects I wish to 'test', instead of a regexy thing that looks for all projects in the tests folder?
I tried something like this, but it failed:
- task: DotNetCoreCLI#2
inputs:
command: test
projects:
- '/tests/Foo1/Foo1.csproj'
- '/tests/Foo4/Foo4.csproj'
arguments: '--configuration $(buildConfiguration)'
displayName: 'dotnet test'
I've just tried it in the web portal and this is the YAML generated:
projects: |
AAA/AAA.csproj
BBB/BBB.csproj
And it didn't work with opening slash, which is also worth mentioning. Hope that helps.
Did any got a working Build Definition in Azure DevOps working for nopCommerce 4.xx working? If so will you please share the YAML-file. I tried several possible solutions, but I don't get it work.
I used the default ASP.NET Core template from Azure Devops. See below YAML
content: resources:
- repo: self queue: name: Hosted Ubuntu 1604
steps:
- task: DotNetCoreCLI#2 displayName: Restore inputs:
command: restore
projects: '$(Parameters.RestoreBuildProjects)'
- task: DotNetCoreCLI#2 displayName: Build inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2 displayName: Test inputs:
command: test
projects: '$(Parameters.TestProjects)'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2 displayName: Publish inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
zipAfterPublish: True
- task: PublishBuildArtifacts#1 displayName: 'Publish Artifact' inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
At the Build step it gives errors when trying to build the Plugins:
2018-12-16T20:31:51.2431313Z
/home/vsts/work/1/s/src/Build/ClearPluginAssemblies.proj(21,5): error
MSB3073: The command "dotnet
"/home/vsts/work/1/s/src/Build\ClearPluginAssemblies.dll"
"OutputPath=/home/vsts/work/1/s/src/Build/../Presentation/Nop.Web/bin/Release/netcoreapp2.1/|PluginPath=/home/vsts/work/1/s/src/Plugins/Nop.Plugin.DiscountRules.CustomerRoles/../../Presentation/Nop.Web/Plugins/DiscountRules.CustomerRoles/|SaveLocalesFolders=""
exited with code 1.
Anyone an idea how to get this working?
Edit:
The response of Eriawan give me some insight to look further. I investigated the csproj files of one of the Plugins and see there the next section:
Thank you for your response. It took me closer to the root cause of the problem (hopefully). I investigated one of the csproj file of the PlugIns of nopCommerce and I see the following section
<!-- This target execute after "Build" target -->
<Target Name="NopTarget" AfterTargets="Build">
<!-- Delete unnecessary libraries from plugins path -->
<MSBuild Projects="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" Properties="PluginPath=$(MSBuildProjectDirectory)\$(OutDir)" Targets="NopClear" />
</Target>
Is there a way to turn off these extra execution during build? or to get this work during build, without adjust the csproj file (because I want to adopt future changes of the project)?
If you are using YAML as option for your Azure Pipelines, you should pay attention to the sequence for the build. Also don't mix YAML with build definition, because YAML is different from the old build definition used by TFS and VSTS (before it changed name to be Azure DevOps).
Looking at the YAML, you should have a full build on your DotNetCoreCLI#2 task, by executing command build. The error you have is a little bit cryptic, but it shows that you just execute dll directly and this means you are going to execute the dll instead of doing actual build.
So instead of this:
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
It should be this:
- task: DotNetCoreCLI#2
displayName: Build
command: build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
Notice the additional command: build.