1

My Azure DevOps Pipeline needs to access some NuGet packages stored in Azure DevOps Artifacts feed.

The package source artifact is defined in <packageSources> of nuget.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="xxx" value="https://pkgs.dev.azure.com/xxx/_packaging/xxx/nuget/v3/index.json" />
  </packageSources>
</configuration>

The dotnet restore works because of the vstsFeed input:

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

The dotnet publish goes in 401 when access to the Artifacts feed. So I follow the hint from https://stackoverflow.com/a/57263923 and added the --no-restore parameter. Now it works:

- task: DotNetCoreCLI@2
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) --no-restore'
    zipAfterPublish: True

But now the dotnet ef migrations do not works: build failed.

YAML:

- task: DotNetCoreCLI@2
  inputs:
    command: 'custom'
    custom: 'ef'
    arguments: 'migrations script --startup-project xxx/xxx.Portal/xxx.Portal.csproj --project xxx/xxx.Core/xxx.Core.csproj --output $(Build.ArtifactStagingDirectory)/SQL/migrate.sql --context Dbxxx --idempotent'

I tried with --no-build ...:

- task: DotNetCoreCLI@2
  inputs:
    command: 'custom'
    custom: 'ef'
    arguments: 'migrations script --no-build --startup-project xxx/xxx.Portal/xxx.Portal.csproj --project xxx/xxx.Core/xxx.Core.csproj --output $(Build.ArtifactStagingDirectory)/SQL/migrate.sql --context Dbxxx --idempotent'

... but another error come:

The specified deps.json [D:\a\1\s\xxx\xxx.Portal\bin\Debug\net5.0\xxx.Portal.deps.json] does not exist

Also adding the feedsToUse and vstsFeed inputs changes nothing:

- task: DotNetCoreCLI@2
  inputs:
    command: 'custom'
    custom: 'ef'
    arguments: 'migrations script --startup-project xxx/xxx.Portal/xxx.Portal.csproj --project xxx/xxx.Core/xxx.Core.csproj --output $(Build.ArtifactStagingDirectory)/SQL/migrate.sql --context Dbxxx --idempotent'
    feedsToUse: 'select'
    vstsFeed: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
Stefano
  • 313
  • 1
  • 4
  • 13
  • 1
    Could you try adding a dotnet task to run build command to build the project before the dotnet task executing dotnet ef migrations with `--no-build`? – Levi Lu-MSFT Mar 29 '21 at 06:47
  • Now it works. I had to add 2 tasks: nuget restore & build with --no-restore. Thanks!!! Now I will try to rationalize YAML because I have double tasks. – Stefano Mar 30 '21 at 07:50
  • That's great you fixed it. You share the fix in the answer thread in case someone finds it useful. – Levi Lu-MSFT Mar 30 '21 at 08:00

1 Answers1

1

Thanks to the Levi Lu-MSFT comment I've fixed my YAML adding 2 tasks before the ef migrations one.

Because Azure DevOps do not allow user to specify the authorization to access the private Azure DevOps Artifacts Feed on the restore operation in build and ef migrations tasks, the correct sequence is:

  1. restore task with authorization by feedsToUser and vstsFeed
  2. build task with --no-restore parameter
  3. ef migrations task with --no-build parameter

So the complete YAML is:

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: 'xxx/xxx.Portal'
    arguments: '--no-restore'

- task: DotNetCoreCLI@2
  inputs:
    command: 'custom'
    custom: 'ef'
    arguments: 'migrations script --no-build --startup-project xxx/xxx.Portal/xxx.Portal.csproj --project xxx/xxx.Core/xxx.Core.csproj --output $(Build.ArtifactStagingDirectory)/SQL/migrate.sql --context Dbxxx --idempotent'
Stefano
  • 313
  • 1
  • 4
  • 13