I have a build pipeline, where I have a Nuget restore step using NuGetCommand which works fine.
But the next step where the build is performed fails on missing nuget packages.
It seems the build step tries to restore the nuget packages a second time, which does not work (It doesn't have the credentials to do so)
The yaml file for the build definition is as follows:
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: CopyFiles@2
displayName: 'copy sql scripts'
inputs:
SourceFolder: 'Resources/TestProject/Migrations/Sql'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)/SqlScripts'
- task: NuGetCommand@2
displayName: 'NuGet Restore'
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: './nuGet.config'
externalFeedCredentials: 'TelerikFeed'
- task: DotNetCoreCLI@2
displayName: 'Build ServiceHost projects'
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/ServiceHosts/**/*.csproj'
arguments: '-c Release -r win-x64 --self-contained false -o $(Build.ArtifactStagingDirectory) /p:SourceRevisionId=$(Build.SourceVersion)'
zipAfterPublish: false
- task: PublishBuildArtifacts@1
displayName: 'Publish artifacts'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
I also have a nuGet.config file which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- remove any machine-wide sources with <clear/> -->
<clear />
<add key="MyFeed" value="https://pkgs.dev.azure.com/MyCompany/_packaging/NugetFeed/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Telerik_NuGet" value="https://nuget.telerik.com/nuget" />
</packageSources>
</configuration>
I don't understand why the build step needs to restore the nuget packages again.
Is there a way to point the DotNetCoreCli to the already restored packages?
Edit:
As suggested by @Ibrahim I added the --no-restore to the DotNetCoreCLI task. I then received the following error message:
C:\Program Files\dotnet\sdk\5.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1047: Assets file 'D:\a\1\s\ServiceHosts\TestProject\obj\project.assets.json' doesn't have a target for 'netcoreapp3.1/win-x64'. Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers.
This was mitigated by adding a task to the yaml file to install the newest version of nuget using
- task: NuGetToolInstaller@1
inputs:
versionSpec: 5.9.1
And adding RuntimeIdentifier win-x64 to the csproj files.
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>TestProject</AssemblyName>
<RootNamespace>TestProject</RootNamespace>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
build
andpublish
both do a restore. You can tell it to not do a restore by passing the appropriate command line argument,--no-restore
. – Daniel Mann