.NET Core CLI task

Azure Pipelines

Use this task in a build or release pipeline to build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.

YAML snippet

# .NET Core
# Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
- task: DotNetCoreCLI@2
  inputs:
    #command: 'build' # Options: build, push, pack, publish, restore, run, test, custom
    #publishWebProjects: true # Required when command == Publish
    #projects: # Optional
    #custom: # Required when command == Custom
    #arguments: # Optional
    #publishTestResults: true # Optional
    #testRunTitle: # Optional
    #zipAfterPublish: true # Optional
    #modifyOutputPath: true # Optional
    #feedsToUse: 'select' # Options: select, config
    #vstsFeed: # Required when feedsToUse == Select
    #includeNuGetOrg: true # Required when feedsToUse == Select
    #nugetConfigPath: # Required when feedsToUse == Config
    #externalFeedCredentials: # Optional
    #noCache: false 
    restoreDirectory: 
    #verbosityRestore: 'Detailed' # Options: -, quiet, minimal, normal, detailed, diagnostic
    #packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' # Required when command == Push
    #nuGetFeedType: 'internal' # Required when command == Push# Options: internal, external
    #publishVstsFeed: # Required when command == Push && NuGetFeedType == Internal
    #publishPackageMetadata: true # Optional
    #publishFeedCredentials: # Required when command == Push && NuGetFeedType == External
    #packagesToPack: '**/*.csproj' # Required when command == Pack
    #configuration: '$(BuildConfiguration)' # Optional
    #packDirectory: '$(Build.ArtifactStagingDirectory)' # Optional
    #nobuild: false # Optional
    #versioningScheme: 'off' # Options: off, byPrereleaseNumber, byEnvVar, byBuildNumber
    #versionEnvVar: # Required when versioningScheme == ByEnvVar
    #majorVersion: '1' # Required when versioningScheme == ByPrereleaseNumber
    #minorVersion: '0' # Required when versioningScheme == ByPrereleaseNumber
    #patchVersion: '0' # Required when versioningScheme == ByPrereleaseNumber
    #buildProperties: # Optional
    #verbosityPack: 'Detailed' # Options: -, quiet, minimal, normal, detailed, diagnostic
    workingDirectory: 

Arguments

ArgumentDescription
Command(Required) The dotnet command to run. Select 'Custom' to add arguments or use a command not listed here.
Publish Web Projects(Required) If true, the task will try to find the web projects in the repository and run the publish command on them. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory.
Path to project(s)(Optional) The path to the csproj file(s) to use. You can use wildcards (e.g. **/.csproj for all .csproj files in all subfolders).
Custom command(Required) The command to pass to dotnet.exe for execution.
Arguments(Optional) Arguments to the selected command. For example, build configuration, output folder, runtime. The arguments depend on the command selected.
Publish test results(Optional) Enabling this option will generate a test results TRX file in $(Agent.TempDirectory) and results will be published to the server.
This option appends --logger trx --results-directory $(Agent.TempDirectory) to the command line arguments.
Zip Published Projects(Optional) If true, folder created by the publish command will be zipped.
Add project name to publish path(Optional) If true, folders created by the publish command will have project file name prefixed to their folder names when output path is specified explicitly in arguments. This is useful if you want to publish multiple projects to the same folder.
Feeds to use(Required) You can either select a feed from Azure Artifacts and/or NuGet.org here, or commit a nuget.config file to your source code repository and set its path here.
Use packages from this Azure Artifacts/TFS feed(Required) Include the selected feed in the generated NuGet.config. You must have Package Management installed and licensed to select a feed here.
Use packages from NuGet.org(Required) Include NuGet.org in the generated NuGet.config.
Path to NuGet.config(Required) The NuGet.config in your repository that specifies the feeds from which to restore packages.
Credentials for feeds outside this organization/collection(Optional) Credentials to use for external registries located in the selected NuGet.config. For feeds in this organization/collection, leave this blank; the build’s credentials are used automatically.
Disable local cache(Required) Prevents NuGet from using packages from local machine caches.
Destination directory(Required) Specifies the folder in which packages are installed. If no folder is specified, packages are restored into the default NuGet package cache.
Verbosity(Required) Specifies the amount of detail displayed in the output.
Path to NuGet package(s) to publish(Required) The pattern to match or path to nupkg files to be uploaded. Multiple patterns can be separated by a semicolon, and you can make a pattern negative by prefixing it with '-:'. Example: **/*.nupkg;-:**/*.Tests.nupkg
Target feed location(Required) undefined
Target feed(Required) Select a feed hosted in this organization. You must have Package Management installed and licensed to select a feed here.
NuGet server(Required) The NuGet service connection that contains the external NuGet server’s credentials.
Path to csproj or nuspec file(s) to pack(Required) Pattern to search for csproj or nuspec files to pack. You can separate multiple patterns with a semicolon, and you can make a pattern negative by prefixing it with '-:'. Example: **/*.csproj;-:**/*.Tests.csproj
Configuration to Package(Optional) When using a csproj file this specifies the configuration to package
Package Folder(Optional) Folder where packages will be created. If empty, packages will be created alongside the csproj file.
Do not build(Optional) Don't build the project before packing. Corresponds to the --no-build command line parameter.
Automatic package versioning(Required) Cannot be used with include referenced projects. If you choose 'Use the date and time', this will generate a SemVer-compliant version formatted as X.Y.Z-ci-datetime where you choose X, Y, and Z. If you choose 'Use an environment variable', you must select an environment variable and ensure it contains the version number you want to use. If you choose 'Use the build number', this will use the build number to version your package. Note: Under Options set the build number format to be '$(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)'.
Environment variable(Required) Enter the variable name without $, $env, or %.
Major(Required) The 'X' in version X.Y.Z
Minor(Required) The 'Y' in version X.Y.Z
Patch(Required) The 'Z' in version X.Y.Z
Additional build properties(Optional) Specifies a list of token = value pairs, separated by semicolons, where each occurrence of $token$ in the .nuspec file will be replaced with the given value. Values can be strings in quotation marks.
Verbosity(Required) Specifies the amount of detail displayed in the output.
Working Directory(Required) Current working directory where the script is run. Empty is the root of the repo (build) or artifacts (release), which is $(System.DefaultWorkingDirectory)
Control options

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A