【问题标题】:Azure DevOps YAML - dotnet core CLI pack builds additional projectsAzure DevOps YAML - dotnet core CLI 包构建其他项目
【发布时间】:2019-11-18 19:50:49
【问题描述】:

我正在尝试打包几个包,但是 --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://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

模板 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"

【问题讨论】:

  • 我认为是因为您在前一步构建了项目,所以存在额外的文件并且pack命令收集它们。
  • @ShaykiAbramczyk 如果我不构建,我会收到包装错误:“文件 'C:\AzureDevOpsPools_work\1\s\src\ProjectA\bin\Release\netstandard2.0\ProjectA.在磁盘上找不到要打包的 dll'。[C:\..\ProjectA.csproj]"
  • 如果你删除 --no-build 你还有额外的文件吗?
  • 对不起,我正在度假,没有笔记本电脑,@HughLin-MSFT 很遗憾没有..

标签: .net .net-core azure-devops yaml azure-pipelines


【解决方案1】:

好吧,我从灰姑娘开始,到科学怪人结束,这是我的发现和对我有用的解决方案。

调查结果

  • 来自 CLI 的所有命令都接受“项目”变量,但 pack 除外, 包需要“packagesToPack”。
  • Pack 需要用“;”分隔的项目而不是新行。
  • Restore 不接受参数“-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

模板 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"

【讨论】:

    【解决方案2】:

    我刚刚遇到这个。我的解决方法是使用自定义命令,其中管道没有注入很好的默认值。

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

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

    【讨论】:

    • ... 这似乎是通过类似-p:version=$(NugetVersion)
    • 不幸的是,对 **/ABC.csproj 等项目的表达不起作用,因为我正在处理的情况将更难维护
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 2019-11-13
    • 2019-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多