Azure DevOps YAML - dotnet core CLI 包构建其他项目

Bru*_*Pro 4 .net yaml .net-core azure-devops azure-pipelines

我正在尝试打包几个包,但是 --no-build 参数或选项被忽略,并且正在构建包括测试项目在内的多个项目。

我尝试了使用“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://learn.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
Run Code Online (Sandbox Code Playgroud)

模板 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"
Run Code Online (Sandbox Code Playgroud)

Bru*_*Pro 6

好吧,我从灰姑娘开始,到弗兰肯斯坦结束,这是我的发现和对我有用的解决方案。

发现

  • CLI 中的所有命令都接受“projects”变量,但 pack 除外,pack 需要“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://learn.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
Run Code Online (Sandbox Code Playgroud)

模板 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"
Run Code Online (Sandbox Code Playgroud)


小智 5

我刚刚遇到过这种情况。我的解决方法是使用自定义命令,其中管道不会注入有意义的默认值。

- 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)'
Run Code Online (Sandbox Code Playgroud)

这仍然让您弄清楚如何覆盖软件包版本。