【问题标题】:Azure pipeline NuGet restore fails to set MsBuild properties in csproj filesAzure 管道 NuGet 还原无法在 csproj 文件中设置 MsBuild 属性
【发布时间】:2020-07-23 16:10:18
【问题描述】:

我正在尝试为 C# 项目设置管道,该项目使用构建配置来决定要安装哪个包。我可以在 Visual Studio 中很好地构建,但是在 Azure Pipelines 上使用 NuGetCommand@2 无法恢复包。看起来在使用该命令时,我在 csproj 文件中创建的属性未设置,因此 NuGet 尝试查找无效版本的包。有没有办法解决这个问题?

csproj:

...
  <PropertyGroup Condition="$(Configuration.Contains('2020'))">
    <RevitVersion>2020</RevitVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Autodesk.Revit.SDK" Version="$(RevitVersion).*" IncludeAssets="build; compile" />
  </ItemGroup>

管道:

...
variables:
  solution: '**/*.sln'
  projects: '**/*.csproj'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release 2020'

steps:
  - task: NuGetToolInstaller@1
    displayName: 'Install NuGet'
    inputs:
        versionSpec: 
  - task: NuGetCommand@2
    displayName: 'Restore packages'
    inputs:
        command: 'restore'
        restoreSolution: '$(solution)'
        configuration: $(buildConfiguration)
        feedsToUse: 'select'
        vstsFeed: '<private feed id>'

错误:

error MSB4018: System.ArgumentException: '.*' is not a valid version string.

【问题讨论】:

    标签: .net nuget azure-pipelines csproj


    【解决方案1】:

    看起来在使用该命令时,我在 csproj 文件未设置,因此 NuGet 尝试查找无效版本 的包。有没有办法解决这个问题?

    Local Nuget Restore command 不支持Configuration 开关。

    Online Nuget task 支持Configuration 开关,但只有nuget pack 命令支持此开关。在线 Nuget 任务有四个命令:Restore,Pack,Push,CustomConfiguration 输入nuget Pack 有效。这就是为什么 nuget pack 会忽略 configuration: $(buildConfiguration) 的原因,即使您在编辑 yaml 管道时没有收到警告/错误。

    该任务的配置输入仅适用于 nuget pack!

    类似讨论请查看link1link2link3

    这是来自Github/Nuget 的建议。您可以尝试使用 Nuget.config 文件和 PAT 为 msbuild /t:restore 提供身份验证。

    【讨论】:

      猜你喜欢
      • 2020-01-09
      • 2020-05-27
      • 2021-08-09
      • 2023-01-17
      • 1970-01-01
      • 2017-04-19
      • 2018-03-28
      • 2018-04-20
      • 1970-01-01
      相关资源
      最近更新 更多