I have a simple .NET solution like below:
My Solution
ClassLibA
ClassLibB
MyAspNetCoreApp
In AzureDevOps pipeline I have also created a simple and straightforward pipeline:
trigger:
- master
pool:
name: 'Default'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
inputs:
version: 6.x
- task: NuGetToolInstaller@0
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: './nuget.config'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: 'MyAspNetCoreApp'
The nuget.config pointed in the NuGetCommand@2 task is as follows:
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="mynuget" value="https://www.azuredevops.web/MyCollection/_packaging/mynuget/nuget/v3/index.json" />
</packageSources>
</configuration>
In fact, I created a nuget feed in AzureDevOps artifacts for my general-purpose libraries and published them into that feed (those libraries are independent of the above solution).
Example:
My Solution
ClassLibA
dependencies
Packages
GeneralLibX (2.0.0)
GeneralLibY (1.1.0)
ClassLibB
MyAspNetCoreApp
The first 3 steps of the pipeline (cloning the solution's repo, installing .NET SDK, installing nuget packages) work fine. However, when the process reaches to the final meat (building the project), it goes bloody with a "Unable to load the service index for source" error.
##[section]Starting: DotNetCoreCLI
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.153.3
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
[command]C:\Windows\system32\chcp.com 65001
Active code page: 65001
[command]C:\AzureDevOpsAgents\winx64\_work\_tool\dotnet\dotnet.exe build C:\AzureDevOpsAgents\winx64\_work\1\s\MyAspNetCoreApp
MSBuild version 17.3.2+561848881 for .NET
Determining projects to restore...
C:\AzureDevOpsAgents\winx64\_work\1\s\ClassLibA\ClassLibA.csproj : error NU1301: Unable to load the service index for source https://www.azuredevops.web/MyCollection/_packaging/mynuget/nuget/v3/index.json. [C:\AzureDevOpsAgents\winx64\_work\1\s\MyAspNetCoreApp\MyAspNetCoreApp.csproj]
C:\AzureDevOpsAgents\winx64\_work\1\s\ClassLibB\ClassLibB.csproj : error NU1301: Unable to load the service index for source https://www.azuredevops.web/MyCollection/_packaging/mynuget/nuget/v3/index.json. [C:\AzureDevOpsAgents\winx64\_work\1\s\MyAspNetCoreApp\MyAspNetCoreApp.csproj]
...
The build process then traps in an unlimited loop and I have no choice but to cancel it.
Could anybody explains why dotnetcli does not build the class libraries in the solution and instead, incorrectly tries to look for their built version in the artifacts' nuget feed?
Thank you in advance.
If you want to build all the
.csprojunder the solution, you can set the value ofprojectsfield to be '**/*.csproj' on theDotNetCoreCLI@2task.In addition, when you run a dotnet command, by default, it will run all the previous processes in the lift-cycle. For example:
dotnet build', it will first run 'dotnet restore' process and then 'dotnet build' process by default.dotnet publish', it will run the previous 'dotnet restore' and 'dotnet build' processes by default, then run 'dotnet publish'.Since you have executed
NuGet restoreusing theNuGetCommand@2task to restore packages before the dotnet build task, you can add the argument '--no-restore' to the dotnet build task to skip the restore process before the build process.So, you can reference below sample to update your YAML:
EDIT:
If your apps are .NET Core or .NET Standard, it is recommended to use the
DotNetCoreCLI@2task to run the 'dotnet restore' command to restore the packages.EDIT_2:
You can try the following ways:
If the feed is in current Azure DevOps organization which the pipeline is in, you can configure the '
dotnet restore' task like as below to authenticate the feed.Or like this when using
nuget.config.If the feed is outside current organization, you can do like as below.
dotnet restore' task like as below.