Working directory parameter of DotNetCoreCL Publish step - azure-devops

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

Related

How to deploy multiple artifacts in a release using Azure devops

We are planning to migrate our current CICD setup which includes Jira and Jenkins, to Azure DevOps but we need suggestion how we can tackle below scenario in Azure DevOps:
We have multiple artifacts in Jira ticket( which can varies from 10 to 200). When we move the ticket to different column in kanban board it triggers jenkins deployment job which deploys all these artifacts at once as one release
But we are not able to find how we can achieve this in azure releases, as it only allows one artifacts in one release. How can we deploy multiple artifacts like above in a release
You could simplify it so instead of deleting the content how about put each artifact in a sub folder of the $(Build.ArtifactStagingDirectory) So by just appending /Api or /App I could create specific publish folders that I could then push onto the azure pipeline.
You can then have as many artifacts as you need.
The important parts to take from this are that publishWebProjects needs to be set to false or it defaults to true and then ignores the projects line below, and the output path puts the content in a sub folder.
# This need to be false in order for the specific project to be published
publishWebProjects: False
projects: '**/DevOpsApp.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/App'
and pathtoPublish need to then point to the sub folder
pathtoPublish: '$(Build.ArtifactStagingDirectory)/App'
Full example file below:
steps:
- task: DotNetCoreCLI#2
displayName: 'Build'
inputs:
command: 'build'
projects: '**/DevOpsApi.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: '**/*Tests.csproj'
arguments: '--configuration $(buildConfiguration)'
testRunTitle: 'Unit Tests'
# Publish the artifact
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
# This need to be false in order for the specific project to be published
publishWebProjects: False
projects: '**/DevOpsApi.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/Api'
zipAfterPublish: True
# Publish the artifact for the pipelines to use
- task: PublishBuildArtifacts#1
displayName: 'Publishing WebAPI Artifact'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)/Api'
artifactName: 'TestWebApi-Wip'

Dotnet test '--filter' is not recognized on Azure DevOps

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.

Azure pipeline: do not build again in order to run tests

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 ;)

Blazor WebAssembly Azure DevOps build pipeline publish artifacts

We created a build pipeline yaml for our blazor webassembly project that includes a publish task. For some reason only the wwwroot folder items get generated into the drop folder, and all the other binaries that are normally located outside of the wwwroot folder are not generated for some reason.
Here is part of the yaml file that builds and publishes. Is it setup incorrectly to get all the files generated and published, or is it just that it will only give us the static files being a webassembly project?
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)"'
zipAfterPublish: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
Also, since we are finding that Blazor webassembly has an issue using the Azure configuration settings for a web service, we are needing to have the publish process manipulate the web.config file so we can set the ASPNETCORE_ENVIRONMENT of the build and deploy. Everything I have found so far does not work when run in the DevOps build pipeline, as they are meant for dotnet scripts.
Does anyone know how this can be done? We have tried to add site /p:EnvironmentName=Development to the --output argument of the publish task, but it says it cannot run on multiple projects, even though we set the projects argument to just the one (it is not shown above as we put it back to normal for now).
Thank you,
Chris Calvert
Did you try this?
task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(buildConfiguration) --output "$(build.artifactstagingdirectory)" /p:EnvironmentName=Development'
zipAfterPublish: True

Working Azure DevOps (aka VSTS) Build Definition for nopCommerce 4.xx

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.