Azure的DevOps的YAML - DOTNET核心CLI包建立额外的项目(Azure De

2019-10-29 07:21发布

我试图收拾几个包,但是--no建造参数或选项被忽略和几个项目,包括试验项目正在建设中。

我已经使用“NoBuild”但由于某些原因额外的项目总是引用,我怎么能不打包生成或在包装使用额外的项目尝试不同的组合?

主要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

模板Yamla:

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"

Answer 1:

我刚刚遇到了这个。 我的解决方法是使用自定义的命令,其中管道不注善意的默认值。

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

这仍然让你搞清楚如何重写包的版本。



Answer 2:

嗯,我开始与灰姑娘并结束了与怪人,这里是我的发现和对我工作的解决方案。

发现

  • 所有的的CLI命令接受除包的“项目”变量,包需要“packagesToPack”。
  • 包需要通过分离项目“;” 而不是新的生产线。
  • 还原没有接受的说法“-s”和读取配置文件来找到一个源所需..

主要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

模板Yamla:

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"


文章来源: Azure DevOps YAML - dotnet core CLI pack builds additional projects