Azure DevOps YAML - dotnet core CLI pack builds ad

2019-08-20 05:47发布

I'm trying to pack several packages, however the --no-build argument or option is being ignored and several projects including test projects are being built.

I have tried different combinations on using "NoBuild" but for some reason extra projects are always referenced, how can i pack without build or using additional projects in pack?

Main YAML:

# ASP.NET Core (.NET Framework)

# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- develop

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  storeBuildNumber:  $(Build.BuildNumber)
  NugetVersion: '1.1.0-unstable'

steps:
- template: AzureDevOps/Templates/provision-template.yml
  parameters:
      projects: |
        **/ProjectA.csproj
        **/ProjectB.csproj

Template YAML:

parameters:
  projects: ''

steps:
- task: DotNetCoreCLI@2
  displayName: "ProvisionRestoreProjects"
  inputs:
    command: 'restore'
    projects: ${{ parameters.projects }}
    arguments: >
      -s "http://MyFeed/nuget/Feed-feature-yaml/"
      -k "ASDF3234234SDSD"

- task: DotNetCoreCLI@2
  displayName: "ProvisionBuildProjects"
  inputs:
    command: 'build'
    projects: ${{ parameters.projects }}
    arguments: '--configuration release  --no-cache'

- task: DotNetCoreCLI@2
  displayName: "ProvisionPackProjects" 
  inputs:
    command: 'pack'
    nobuild: true
    projects: ${{ parameters.projects }}
    versioningScheme: 'byEnvVar'
    versionEnvVar: 'NugetVersion'
    arguments: '--no-build'

- task: DotNetCoreCLI@2
  displayName: "ProvisionPushProjects"
  inputs:
    command: custom
    custom: nuget
    arguments: >
      push "$(Build.ArtifactStagingDirectory)\*.nupkg"
      -s "http://MyFeed/nuget/Feed-feature-yaml/"
      -k "ASDF3234234SDSD"

2条回答
手持菜刀,她持情操
2楼-- · 2019-08-20 06:26

I have just encountered this. My workaround was to use a custom command where the pipeline doesn't inject well meaning defaults.

- task: DotNetCoreCLI@2
  displayName: 'dotnet pack'
  inputs:
    command: 'custom'
    custom: 'pack'
    arguments: 'path/to/project.csproj --no-build --include-symbols --include-source -c=Release -o $(build.artifactstagingdirectory)'

This still leaves you figuring out how to override the package version.

查看更多
别忘想泡老子
3楼-- · 2019-08-20 06:39

Well i started with Cinderella and ended up with Frankenstein, here are my findings and the solution that worked for me.

Findings

  • All commands from the CLI accept the "projects" variable except pack, pack needs "packagesToPack".
  • Pack needs projects separated by ";" and not new lines.
  • Restore didn't accept the argument "-s"and needed to read a config file to find a source..

Solution

Main YAML:

# ASP.NET Core (.NET Framework)

# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- develop

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  storeBuildNumber:  $(Build.BuildNumber)
  NugetVersion: '1.1.0-unstable'

steps:

- task: PowerShell@2
  displayName: "Get Nuget Feed from config"
  inputs:
    targetType: 'inline'
    script: >
      $currentLocation = "$(get-location)"

      cd $(Build.SourcesDirectory)

      #Get file

      $file =  ".\NuGet.Config"

      $content = (Get-Content $file)

      Write-Output ("file content: $content")

      $regex = '(?<=<add key="CurrentBranchFeed" value=")[^"]*'

      Write-Output ("regex: $regex")

      $nugetFeed = [regex]::match($content,$regex).Groups[0].Value

      Write-Output ("Result: $nugetFeed")

      Write-Output ("##vso[task.setvariable variable=NugetFeed;]$nugetFeed")

      cd $currentLocation

- template: AzureDevOps/Templates/provision-template.yml
  parameters:
      projects: |-
        **/ProjectA.csproj
        **/ProjectB.csproj

Template YAML:

parameters:
  projects: ''

steps:
- task: PowerShell@2
  displayName: "UpdateProjectsToPack"
  inputs:
    targetType: 'inline'
    script: '
    $currentProjects = "${{ parameters.projects }}"

    $currentProjects = $currentProjects.replace("`r","")

    $ProjectsToPack = $currentProjects.replace("`n",";")

    Write-Output ("##vso[task.setvariable variable=ProjectsToPack;]$ProjectsToPack")
    '

- task: DotNetCoreCLI@2
  displayName: "ProvisionRestoreProjects"
  inputs:
    command: 'restore'
    projects: '${{ parameters.projects }}'
    feedsToUse: 'config'
    nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.Config'

- task: DotNetCoreCLI@2
  displayName: "ProvisionBuildProjects"
  inputs:
    command: 'build'
    projects: '${{ parameters.projects }}'
    arguments: '--configuration release  --no-cache'

- task: DotNetCoreCLI@2
  displayName: "ProvisionPackProjects" 
  inputs:
    command: 'pack'
    nobuild: true
    packagesToPack: $(ProjectsToPack)
    versioningScheme: 'byEnvVar'
    versionEnvVar: 'NugetVersion'
    arguments: '--no-dependencies --force --no-cache'

- task: DotNetCoreCLI@2
  displayName: "ProvisionPushProjects"
  inputs:
    command: custom
    custom: nuget
    arguments: >
      push "$(Build.ArtifactStagingDirectory)\*.nupkg"
      -s "$(NugetFeed)"
      -k "ASDF3234234SDSD"
查看更多
登录 后发表回答