Azure DevOps 名称中包含 Platform 的 Nuget 包出现问题

问题描述 投票:0回答:1

我有 2 个 nugetpackages,它们遵循命名约定: SomePackage.x86 和 SomePackage.x64

在本地,这些工作通过以下方法进行包引用:

<PackageReference Include="SomePackage.$(Platform)" Version="xx.xx.xx.xx" />

使用 x86 或 x64 的配置集,它们都可以正常工作。 尝试执行 nuget 恢复任务时出现问题:

  - task: NuGetCommand@2
    displayName: Restore Nuget Packages
    inputs:
      restoreSolution: '$(Build.SourcesDirectory)\MySolution\MySolution-$(buildPlatform).sln'
      feedsToUse: config
      nugetConfigPath: '$(Build.SourcesDirectory)\MySolution\.nuget\NuGet.Config'

我在平台矩阵中也确实有这项任务。 所以理想情况下,一个人会构建 x86,一个人会构建 x64

- job: Build
  dependsOn: SetVersion
  strategy:
    maxParallel: 2
    matrix:
      x86:
        buildPlatform: 'x86'
      x64:
        buildPlatform: 'x64'

当管道尝试恢复包时,它显然使用了不正确的平台,如下是错误

 error NU1301: Failed to retrieve information about 'SomePackage.Any CPU' from remote source 'https://somenugeturl/SomePackage.any cpu/index.json'

为了让这个问题变得更加复杂,我在 .NET Framework 4.8 和 .NET 6.0 中进行了编译。

在.net框架中,我可以设置默认平台,这将完成初始构建,但是,我不确定其他平台是否可以正常工作。

我尝试将 nuget 恢复更改为:

arguments: "-Property Platform='x86'"

我也尝试过

dotnet restore "MySolution.sln" --arch x86 

这仍然给我任何CPU错误。

我已经在项目中设置了我的平台和平台目标,它不会改变任何东西:

<Platforms>x86;x64</Platforms>
<PlatformTarget>x64</PlatformTarget>
<TargetFramework>net6.0-windows</TargetFramework>

我想知道是否有处理此类包裹的标准方法?

azure-devops azure-pipelines nuget devops nuget-package-restore
1个回答
0
投票

构建解决方案或项目时,如果不指定构建配置(

buildConfiguration|buildPlatform
),它将使用默认配置“
Debug|Any CPU
”来运行恢复和构建。

要在运行

restore
build
和其他步骤(如
publish
pack
等)时覆盖默认配置,您可以执行以下操作:

variables:
  buildConfiguration: Release

jobs:
- job: build
  strategy:
    matrix:
      x86:
        buildPlatform: 'x86'
      x64:
        buildPlatform: 'x64'
  steps:
  - task: DotNetCoreCLI@2
    displayName: 'Restore Dependences'
    inputs:
      command: 'restore'
      projects: 'path/to/solution.sln'
      restoreArguments: '-p:Configuration=$(buildConfiguration);Platform=$(buildPlatform)'
      feedsToUse: 'config'
      nugetConfigPath: 'path/to/nuget.config'
  
  - task: DotNetCoreCLI@2
    displayName: 'Build Solution'
    inputs:
      command: 'build'
      projects: 'path/to/solution.sln'
      arguments: '--no-restore -c $(buildConfiguration) -p:Platform=$(buildPlatform)'

enter image description here

enter image description here


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.