0

I am doing YAML pipelines in Azure DevOps with C# Visual Studio projects. My test and build pipeline worked fine until I was going to tryout floating NuGet package version number in my C# projects looking like this:

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="*" />
<PackageReference Include="My.Internal.AzureDevOps.Package" Version="*" />

And my pipeline YAML code in Azure DevOps looks like this:

jobs:
  - job: BuildAndTest
    steps:
        
      - task: UseDotNet@2
        inputs:
          packageType: 'sdk'
          version: '6.x'

      - task: DotNetCoreCLI@2
        displayName: 'Restore packages'
        inputs:
          command: 'restore'
          projects: '**/*.csproj'
          feedsToUse: 'select'
          vstsFeed: 'ba262f00-12b3-4448-8346-5795269eb94b/7040e1b7-4758-4ab0-b3bb-ed9d6427d570'

      
      - task: DotNetCoreCLI@2
        displayName: 'Build'
        inputs:
          command: 'build'
          projects: '**/*.csproj'
          arguments: '--configuration release'
      
      - task: DotNetCoreCLI@2
        displayName: 'Test'
        inputs:
          command: 'test'
          projects: '**/*Tests.csproj'
          arguments: '--configuration release'

So when I ran the same pipeline but with floating version numbers in my C# project the build step fails because it cannot find my local Azure DevOps nuget packages. Restore task works fine as I point out my local Azure DevOps Nugets with vstsFeed but the build task does not. Why can't my build task find the nugets?

What I understand there is no support for vstsFeed in the build step (I have tried, throws an error) and any authorization should be done and set in the restore task (I've tried that also in all different ways but failed). Any how does the restore task work without any authorization but the build step does not. I don't exactly how DotNetCoreCLI does the build step but it feels like it does like Visual Studio does when building, get and check for the latest nuget version available and use that but DotNetCoreCLI doesn't get access to get the nuget versions or finds/get the paths, like in my case the local vstsFeed. I have spent more then 1 day on this trying all different things with no success.

2
  • Does a floating version against a major version work, e.g. <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />? A change in the major version indicates an incompatible change. (* should be supported though) Commented Nov 10, 2023 at 21:48
  • Yes I notice Visual Studio accepts * and 17.* and 17.1.*. Commented Nov 13, 2023 at 7:22

1 Answer 1

0

I can reproduce the issue when I build a .NET 6 project on self-hosted agent using DotNetCoreCLI task.

Error NU1101: Unable to find package Fortest. No packages exist with this id in xxxx.

In dotnet build, DotNet restore runs implicitly. As the restore step is successful, you can add the argument '--no-restore' to disable restore in build step.

- task: DotNetCoreCLI@2
  displayName: 'Build'
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration release --no-restore'
  

Or you can add Nuget.config file in your project folder and set vstsFeed you want to use.

<packageSources>
    <add key="Source" value="vstsFeed" />
</packageSources>
<config>
    <add key="globalPackagesFolder" value="your package folder" />
 </config>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! So it was so easy to solve with only "--no-restore". I got the same issue on the test step but "--no-restore" solve it there as well. I haven't tried solving it with Nuget.config yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.