Home > OS >  Azure pipeline tasks ignoring configuration when restoring packages
Azure pipeline tasks ignoring configuration when restoring packages

Time:10-19

I have Azure pipeline tasks that authenticate against the ADO Artifact feed, restore the packages, and then build the Visual Studio solution, all targeting a configuration.

When I run the pipeline with variable buildConfiguration set to Release, I expect Components.Library package 0.1.66 to be restored.

What is actually happening is that the tasks look for package version 0.0.0 and then makes a (wildly inaccurate) approximation of which version to restore.

I have carried out the following troubleshooting steps:

  • Confirmed that buildConfiguration variable is what is expected via the Testing task
  • Set pipeline variable buildConfiguration to Release just to see if anything changes (no difference)
  • Hardcoded the configuration: "Release" (no difference)
  • Pointed the tasks at both solution and project files (no difference)

Any and all help as to why the configuration is being ignored would be greatly appreciated.

A few notes:

  • NuGetCommand is being used to restore and not DotNetCli as the latter does not support a configuration to be passed
  • VSBuild is being used for the build as it's the best fit. Same behaviour seen when using the MSBuild task

/azure-pipelines.yml (snippet)

- task: AzureCLI@2
  name: DeployTesting
  displayName: Testing
  inputs:
    azureSubscription: $(subscription)
    scriptType: pscore
    scriptLocation: inlineScript
    inlineScript: |
      Write-Host $(buildConfiguration)

- task: NuGetAuthenticate@0
  name: NuGetAuthenticate
  displayName: Feed Authenticate

- task: NuGetCommand@2
  name: NuGetRestore
  displayName: Restore Solution
  inputs:
    command: "restore"
    feedsToUse: "select"
    vstsFeed: "MyProject/MyFeed"
    includeNuGetOrg: true
    restoreSolution: "**/*.csproj"
    configuration: "$(buildConfiguration)"

- task: VSBuild@1
  name: BuildSolution
  displayName: Build Solution
  inputs:
    solution: "**/*.sln"
    configuration: "$(buildConfiguration)"

/ui.sln

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31410.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UI", "UI\UI.csproj", "{7C638A83-CB99-4D21-BA60-4B124FDFCB95}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {7C638A83-CB99-4D21-BA60-4B124FDFCB95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {7C638A83-CB99-4D21-BA60-4B124FDFCB95}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {7C638A83-CB99-4D21-BA60-4B124FDFCB95}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {7C638A83-CB99-4D21-BA60-4B124FDFCB95}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {05622357-F4B9-43A7-8DFE-ACAC7BBD0F2C}
    EndGlobalSection
EndGlobal

/ui/ui.csproj

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <Configurations>Debug;Release</Configurations>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Fluxor.Blazor.Web" Version="4.1.0" />
        <PackageReference Include="Fluxor.Blazor.Web.ReduxDevTools" Version="4.1.0" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.11" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.11" PrivateAssets="all" />
        <PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
    </ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Debug'">
    <PackageReference Include="Components.Library" Version="0.0.0-local" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Release'">
    <PackageReference Include="Components.Library" Version="0.1.66" />
</ItemGroup>

</Project>

Task Output

GET https://pkgs.dev.azure.com/MyFeed/73b2138a-b811-4cfd-a42d-e3265183c9f7/_packaging/b942ec16-9557-4c7c-b6e8-97d2a7095a98/nuget/v3/flat2/components.library/0.1.2/components.library.0.1.2.nupkg

##[warning]OUI\UI.csproj(0,0): Warning NU1603: UI depends on Components.Library (>= 0.0.0-local) but Components.Library 0.0.0-local was not found. An approximate best match of Components.Library 0.1.2 was resolved.

CodePudding user response:

It would appear that NuGetCommand@2 does not honour the configuration passed, even when the following is added to the task:

arguments: /p:Configuration=$(buildConfiguration)

Adding the following pipeline variable resolved the issue:

- name: NUGET_RESTORE_MSBUILD_ARGS
  value: "/p:Configuration=$(BuildConfiguration)"

Thanks to @yhyrcanus in their reply here - https://stackoverflow.com/a/68986694/14985216

CodePudding user response:

Since you rely on .NET Core/.NET 5, I'd recommend using the dotnet task with the restore command instead of using nuget task. It's a lot more aware of msbuild and project files.

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.sln'
    restoreArguments: '/property:Configuration=$(BuildConfiguration)'
    feedsToUse: 'select'
    vstsFeed: 'MyProject/MyFeed'

I'd also recommend pointing to the .sln file instead of **/*.csproj, since that's also how you're building the code.

  • Related