Using dotnetcore cli the packages are being generated with a packagetype node, causing Visual Studio to not be able to install the package.
Building the package on Visual Studio does not generate the node, but on dotnetcore cli it gets generated in CI like this:
<packageTypes>
<packageType name="api" />
</packageTypes>
CI steps:
- task: DotNetCoreCLI#2
displayName: "${{ parameters.name }} - Restore"
inputs:
command: 'restore'
projects: '${{ parameters.projects }}'
feedsToUse: 'config'
nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.Config'
- task: DotNetCoreCLI#2
displayName: "${{ parameters.name }} - Build"
inputs:
command: 'build'
projects: '${{ parameters.projects }}'
arguments: "--configuration Release --no-cache"
- task: DotNetCoreCLI#2
displayName: "${{ parameters.name }} - Pack"
inputs:
command: 'pack'
nobuild: true
packagesToPack: $(ProjectsToPack)
versioningScheme: 'byEnvVar'
versionEnvVar: 'NugetVersion'
arguments: '--no-dependencies --force --no-cache'
- task: DotNetCoreCLI#2
displayName: "${{ parameters.name }} - Push"
inputs:
command: custom
custom: nuget
arguments: >
push "$(Build.ArtifactStagingDirectory)\*.nupkg"
-s "$(NugetFeed)"
-k "$(NugetToken)"
How can i disable it?
I can't reproduce same issue in Build Pipeline.
For me, the PackageType will be generated only when I specify the <PackageType>api</PackageType> in project file(csproj) or I define the packageTypes elements in xx.nuspec.
How can i disable it?
So I suggest you check if there's any definition about PackageType defined in your project file or in the xx.nuspec file in project folder. Find it, delete it and this issue won't occur.
(The 'api' indicates you or someone in your team define the PackageType in your team project, see this, different from Dependency and DotnetCliTool, api is apparently a custom PackageType)
Apart from above, you can also try adding arguments --no-dependencies --force --no-cache --configuration Release -p:PackageType="" to your dotnet pack task. Using -p:PackageType="" in command-line can disable the behavior in my machine. Hope it helps :)
It turns out "PackageType" became similar to a reserved word when using DotNetCli, changed the variable name to "ApplicationType" to avoid having the package type in the nuscpec.
Write-Output ("##vso[task.setvariable variable=PackageType;]$packageType")
Related
I have dotnet core project and using 'DotNetCoreCLI#2' task in Azure Pipeline to publish the code. My 'DotNetCoreCLI#2' task looks like this:
- task: DotNetCoreCLI#2
displayName: 'Dotnet Publish'
inputs:
command: 'publish'
publishWebProjects: false
projects: |
**/*.csproj
!**/*Blazor.csproj
arguments: '-o $(Build.ArtifactStagingDirectory)'
This works when used. Now I am trying to build template and want to pass projects values as variables or parameters but failing to do so.
Here is what I tried (I am using variable here)
variables:
projectsToPublish: '**/*.csproj;!**/*Blazor.csproj'
steps:
- task: DotNetCoreCLI#2
displayName: 'Dotnet Publish'
inputs:
command: 'publish'
publishWebProjects: false
projects: $(projectsToPublish)
arguments: '-o $(Build.ArtifactStagingDirectory)'
I also tried using variables like this, but it didn't work and keep getting this error message: ##[error]Project file(s) matching the specified pattern were not found.
variables:
projectsToPublish: '|
**/*.csproj
!**/*Blazor.csproj'
or
variables:
projectsToPublish: '**/*.csproj
!**/*Blazor.csproj'
Any idea how I can set projects values in variables and use it in publish task?
how I can set projects values in variables and use it in publish task?
To solve this issue, you can define multiple line variable in Azure Pipeline.
For example:
variables:
projectsToPublish: |
**/*.csproj
!**/*Blazor.csproj
steps:
- task: PowerShell#2
inputs:
targetType: 'inline'
script: echo "$(projectsToPublish)"
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: false
projects: |
$(projectsToPublish)
Result:
You could use parameters for a try.
Firstly, ensure in your repo the '/*.csproj;!/*Blazor.csproj' files do exist.
Then you could try this:
parameters:
- name: projectsToPublish
type: string
values:
- '**/*.csproj'
- '!**/*Blazor.csproj'
steps:
- task: DotNetCoreCLI#2
displayName: 'Dotnet Publish'
inputs:
command: 'publish'
publishWebProjects: false
projects: ${{ parameters.projectsToPublish}}
arguments: '-o $(Build.ArtifactStagingDirectory)'
For parameters execute in runtime, you will need to choose the value after click run:
[![enter image description here][1]][1]
Choose one then click 'run', then you are supposed to run the task.
[1]: https://i.stack.imgur.com/2uoPk.png
I have these variables for my pipeline:
variables:
webProject: 'Company.Web'
dbProject: 'Company.Database'
And then later, I use those variables in a dotnet cli task:
# stage/job setup
- task: DotNetCoreCLI#2
displayName: Clean
inputs:
command: custom
projects: '**/$(webProject).csproj'
custom: clean
arguments: '--configuration "$(BuildConfiguration)"'
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: custom
custom: restore
projects: |
'**/$(webProject).csproj'
'**/$(dbProject).csproj'
# rest of yaml
When I run the pipeline, I get this error: Project file(s) matching the specified pattern were not found.
What is strange is it works ok for the clean task, but the restore fails. I was able to confirm with a echo script the variable is being rendered correctly. I also am able to replace the variable with the variable text in the script and it runs just fine when I do that. Any idea what I am missing here?
Although the documentation doesn't specifically state this, I'm expecting it's because you're including two glob patterns. You can either try **/*.csproj, or include two relative path with no wildcard characters, i.e.
src/Foo.csproj
src/Bar.csproj
In the documentation there is a section for Extended Globbing that explains how to match multiple projects.
If you are like me and only need to run a command against specific projects (while still using wildcards) and preserve variables/parameters for templating, this is the way to go.
How it worked for me:
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: custom
custom: restore
projects: '**/*($(dbProject)|$(webProject)).csproj'
Try to use this sintax
inputs:
command: custom
projects: ${{ variables.webProject }}
custom: clean
arguments: '--configuration "$(BuildConfiguration)"'
If you use templates, then you should pass the variable as a parameters from the azure-pipelines.yml
azure-pipelines.yml
- template: myTemplate.yml
parameters:
projects : ${{ variables.webProject }}
myTemplate.yml
- task: DotNetCoreCLI#2
displayName: Clean
inputs:
command: custom
projects: "${{ parameters.webProject }}".csproj
custom: clean
arguments: '--configuration "$(BuildConfiguration)"'
- task: DotNetCoreCLI#2
displayName: Build X (DotNet)
inputs:
command: 'build'
projects: '$(X)'
arguments: '-c "Release" /p:Platform="x64" --output $(Build.ArtifactStagingDirectory)\X'
once I adding the output (--output $(Build.ArtifactStagingDirectory)\X') argument for be able to PublishArtifact after that the build results.
I got error from solution of missing's files in the Build Solution: error MSB3073
and if I remove the output is work good but I have no option to publishArtifact the results
to some 1 have suggestion how can I publish the results to artifact without output? or to solve the output issue
I am not sure if the --output parameter is available. You can alternatively build your solution using your task and add a separate powershell task to copy build directory to your requested folder. For example:
- task: PowerShell#2
displayName: Copy code output to artifactsStagingDirectory
inputs:
targetType: 'inline'
script: 'Move-Item "$(Build.SourcesDirectory)/src/solutionName/bin/Debug" "$(Build.ArtifactStagingDirectory)/X"'
I have a problem that I have failed to resolve.
I have a .NET core project that I want to run tests and publish the test coverage on Azure Pipelines.
The problem is: I'm using EF to generate Migrations files. I want to ignore these files from test
but I can't.
Anyone how to do add some arguments to the pipe-lines command to ignore these files? like --exclude Migrations/*.cs
Here is the job in my azure-pipelines.yaml
- job: Testing
steps:
- task: UseDotNet#2
displayName: 'Use .Net Core sdk 3.1.x'
inputs:
version: 3.1.x
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: '$(build.sourcesDirectory)/tests/*Tests/*.csproj'
arguments: -c $(BuildConfiguration) --logger trx --collect:"XPlat Code Coverage" --settings:$(build.sourcesDirectory)/src/test.runsettings -- RunConfiguration.DisableAppDomain=true
displayName: 'run tests'
- task: DotNetCoreCLI#2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool
- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"Cobertura"
displayName: Create reports
- task: PublishCodeCoverageResults#1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml
You're probably looking for -classfilters or -filefilters.
https://github.com/danielpalme/ReportGenerator
I use -classfilter like this, where Foo.Bar.* and Foo.Baz.* is the namespace i want to exclude in the report:
variables:
...
classes-to-exclude-from-coverage: "-Foo.Bar.*;-Foo.Baz.*"
...
- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"HtmlInline_AzurePipelines;Cobertura;Badges" -assemblyfilters:"-xunit*;" -classfilters:'$(classes-to-exclude-from-coverage)'
displayName: Create reports
Good morning,
Sorry to bother you, I have a problem and I have no leads.
I have a pipeline on Azure DevOps where I use coverlet to generate a code coverage report when I use the command "dotnet test".
Indeed, the report is well generated.
At first, in the "Prepare analysis on SonarQube" step, I set the variable "sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml".
And yet the end in my SonarQube there is 0% code coverage... I don't know what to do or any leads...
Thanks
I cannot reproduce above issue. And it is hard to troubleshoot since you did not share your configuration for dotnet test task or sonarqube prepare task.
I created a test project and the coverage was successfully published to my sonarqube server. You can refer to below my steps.
1, create sonarqube server and configure my projectName and projectKey (I use azure sonarqube container instance, check here for details).
2, configure sonarqube service connection in azure devops.
3, create build pipeline. I use yaml pipeline.
In Prepare Analysis Configuration task, I choose to Use standalone scanner, and Mode is Manually provide configure. And I set variable sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml".
Below screenshot is the task's setting in classic ui view.
In my dotnet test task I set the arguments as below, and specifically output the coverage result to $(Agent.TempDirectory)/ folder.
arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.TempDirectory)/ /p:CoverletOutputFormat=opencover'
Below is the full content of my azure-pipelines.yml file.
trigger: none
jobs:
- job: 'Tests'
pool:
vmImage: windows-latest
variables:
buildConfiguration: 'Release'
continueOnError: true
steps:
- task: SonarQubePrepare#4
displayName: 'Prepare analysis on SonarQube'
inputs:
SonarQube: sonarlevi
scannerMode: CLI
configMode: manual
cliProjectKey: myproject2
cliProjectName: myproject2
extraProperties: |
sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml"
- task: DotNetCoreCLI#2
inputs:
command: restore
projects: '**\*.csproj'
- task: DotNetCoreCLI#2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool
- task: DotNetCoreCLI#2
displayName: Test .NET
inputs:
command: test
projects: '**\*Test*.csproj'
publishTestResults: false
arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.TempDirectory)/ /p:CoverletOutputFormat=opencover'
condition: succeededOrFailed()
- task: SonarQubeAnalyze#4
displayName: 'Run Code Analysis'
- task: SonarQubePublish#4
displayName: 'Publish Quality Gate Result'
I did a lot of things to finally managed to get the coverage working but I think that the problem was the "ProjectGUID" missing in each .csproj of my solution making the projects ignored by SonarQube scanner.
I also upgraded from SonarQube 6.2 to 8.1 at the same time which may have solved the problem.
My steps remained unchanged to make this work.