Telerik Nuget package restore in Azure build pipeline fails - azure

I'm attempting to pull Nuget packages from Telerik's Nuget repository into an Azure build pipeline, however, none of the pipeline configuration attempts I've made seem to work. I either receive an error stating my nuget.config is not formatted correctly or a 401 error when connecting to the repository.
The below configuration section is from my build definition. I've tried using NuGetCommand as well as NuGetRestore:
- task: NuGetToolInstaller#1
inputs:
versionSpec: '5.0.2'
- task: NuGetAuthenticate#1
inputs:
nuGetServiceConnections: 'Telerik_v3'
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: './XXXXXXX/nuget.config'
#'$(System.DefaultWorkingDirectory)/XXXXXXX/NuGet.config'
externalFeedCredentials: 'Telerik_v3'
# - task: NuGetRestore#1
# inputs:
# solution: '**/*.sln'
# selectOrConfig: 'config'
# nugetConfigPath: './XXXXXXX/nuget.config'
Here is my nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
<add key="Telerik_NuGet" value="https://nuget.telerik.com/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
Here is the error I receive:
NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://nuget.telerik.com/v3/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
Tweaking the configuration slightly I get this error:
##[error]The nuget command failed with exit code(1) and error(NuGet.Configuration.NuGetConfigurationException: NuGet.Config is not valid XML. Path: 'D:\a\1\Nuget\tempNuGet_966.config'. ---> System.Xml.XmlException: An error occurred while parsing EntityName. Line 10, position 46.
I based my build tasks on the NuGetCommandv2 and NuGetRestore v1 documentation as well as what I found on Telerik's site.

When we want to use private nuget packages like Telerik we need to specify credentials in Nuget.config_
Connection name
Feed URL
Username
Password
NOTE:
In order to add a reference to this NuGet package to your project, firstly need to add Telerik credentials into Visual Studio.
example:
dotnet nuget update source "Telerik" --source "https://nuget.telerik.com/v3/index.json" --configfile "nuget.config" --username '*************' --password '***********' --store-password-in-clear-text
Here I found one reference github by Lance McCarthy

Related

Azure build pipeline unable to restore NuGet packages from private feed when using NuGet.Config file from solution

I am trying to build a C# project in DevOps build pipeline. The project is using a single Azure Artifacts private feed. The NuGet.config is as given by the Azure portal from the Nuget tab of connect feed page. The file is at the root of the solution.
NuGet.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositorypath" value=".\packages" />
<packageSources>
<clear />
<add key="<myfeedname>" value="https://pkgs.dev.azure.com/<myorg>/<myproject>/_packaging/<myfeedname>/nuget/v3/index.json" />
</packageSources>
</config>
</configuration>
I am having difficulty restoring packages when using NuGet.config from the solution. The log shows some evidence of using the azure org related URLs but not the project or feed. The restore cannot find packages. However, if I specify the feed and package folder in the NuGet restore task itself, it works fine and downloads all packages. I am expecting the task to find the private feed URL automatically from the NuGet.config file, authenticate (since inside pipeline), and download packages. The config file works fine in local builds asking for org user credentials (pop up) when using VS. The NuGet.config is checked into repo and hence there are no credentials used.
I also have NuGet Authenticate task just in case. (The working version doesn't even need this task).
- task: NuGetAuthenticate#0
What is wrong with the non-working version?
Working Version:
- task: NuGetCommand#2
displayName: "Step: Restore NuGet"
inputs:
command: 'restore'
feedsToUse: 'select'
vstsFeed: '<myproject>/<MyFeed>'
includeNuGetOrg: false
restoreSolution: '$(solution)'
restoreDirectory: "../../packages"
verbosityRestore: Detailed
continueOnError: true
Non-Working Version:
- task: NuGetCommand#2
displayName: "Step: Restore NuGet"
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'config'
nugetConfigPath: "NuGet.config"
verbosityRestore: Detailed
continueOnError: true
From non-working version, the log shows that it is using the file as expected.
C:\hostedtoolcache\windows\NuGet\5.8.1\x64\nuget.exe restore D:\a\1\s\<solution-file-path> -Verbosity Detailed -NonInteractive -ConfigFile D:\a\1\s\NuGet.config
NuGet Version: 5.8.1.7021
Some errors:
WARNING: Unable to find version '6.0.0' of package 'Microsoft.CodeAnalysis.NetAnalyzers'.
NU1100: Unable to resolve 'AsyncFixer (>= 1.5.1)' for '.NETFramework,Version=v4.8'.
I also find some logs related to devops org for auth but no mention of project or feed name,
##[debug]Discovered URL prefixes: https://dev.azure.com/<my-org>/,.....others....
:
##[debug]Got auth token
..
:
##[error]Packages failed to restore
No mention of NuGet sources used in log. (System.Debug set to true in variables)
The working version shows the private feed as source used at the end.
NuGet Config files used:
D:\a\1\Nuget\tempNuGet_2852.config
Feeds used:
https://pkgs.dev.azure.com/<org>/<proj>/_packaging/<feed>/nuget/v3/index.json
However, I want to use the config version since it seems to be the right approach.

AzureDevops Task name NuGetCommand is ambiguous

I am getting the following error when trying to run my pipeline
Job Job: Step task reference is invalid. The task name NuGetCommand is ambiguous.
Specify one of the following identifiers to resolve the ambiguity:
.NuGetCommand, .NuGetCommand
Below is my .yml file for my .Net Standard library
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/MyLibrary.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/MyLibrary.sln'
feedsToUse: 'config'
nugetConfigPath: './nuget.config'
- task: VSBuild#1
inputs:
solution: '**\MyLibrary.sln'
vsVersion: '15.0'
restoreNugetPackages: true
It seems to be complaining about NugetCommand#2 which doesn't make sense when it comes built in?
Edit
Have also tried using - task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b#2 instead of - task: NuGetCommand#2
One may have been pushed straight into the account using tfx build tasks upload, run tfx build tasks list to find out which ones are installed and if needed delete the non-official one using tfx build tasks delete.
C:\Users\jesse>npm install tfx-cli -g
C:\Users\jesse>tfx build tasks list
TFS Cross Platform Command Line Interface v0.8.3
Copyright Microsoft Corporation
> Service URL: https://dev.azure.com/jessehouwing-dev
> Personal access token:
The one you want to keep is:
id : 333b11bd-d341-40d9-afcf-b32d5ce6f23b
name : NuGetCommand
friendly name : NuGet
visibility :
description : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
version : 2.179.0
If there is one with a different guid, delete is with:
C:\Users\jesse>tfx build tasks delete --task-id the-task-id-guid-to-delete
It may also have been pushed as part of a privately shared custom extension. The marketplace will block tasks with the rame GUID, but it will allow installing a task with the same name just fine through an extension. Check your installed extensions, especially privately shared ones.
AzureDevops Task name NuGetCommand is ambiguous
According to the error message, it seems that error can happen when two tasks\extensions exist in your Azure DevOps organization with the same name.
You could use this REST API:
https://dev.azure.com/{organisationName}/_apis/distributedtask/tasks?visibility%5B%5D=Build
to check here for possible duplicates.
To resolve this issue, you could use command line to invoke nuget.exe to restore the solution:
nuget.exe restore a.sln -source "xx" -PackagesDirectory

Fail to execute "dotnet tool restore --interactive" in Build Pipeline when using Azure DevOps Artifact

I'm using Azure DevOps and would like to run dotnet tool restore --interactive in my Build Pipeline. In my code repo, there is nuget.config as follows. The file has a private feed hosted in Azure Artifact in addition to nuget.org.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="MyTools" value="https://mytools.pkgs.visualstudio.com/MyBot/_packaging/MyTools/nuget/v3/index.json" />
</packageSources>
</configuration>
In the private feed in Azure Artifact, my private dotnet tools exist. To retrieve the tool I created following yml file.
pool:
vmImage: "windows-latest"
demands:
- msbuild
- visualstudio
- vstest
variables:
buildPlatform: "Any CPU"
buildConfiguration: "Release"
steps:
- task: PowerShell#2
inputs:
targetType: inline
script: "Invoke-WebRequest -Uri https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1 -OutFile ./installcredprovider.ps1 ;./installcredprovider.ps1;"
- task: DotNetCoreCLI#2
displayName: "Restore tools"
inputs:
command: custom
custom: tool
arguments: restore --interactive
However, as I run the yml file in the build process, following result appears. As the message shows, it requires sign-in, but I do not want to do device sign-in every time. So Is there any good way so that I do not have to do device log-in every time?
##[section]Starting: Restore tools
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.162.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
[command]"C:\Program Files\dotnet\dotnet.exe" tool restore --interactive
Welcome to .NET Core 3.1!
---------------------
SDK Version: 3.1.100
Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
----------------
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Find out what's new: https://aka.ms/dotnet-whats-new
Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs
Write your first app: https://aka.ms/first-net-core-app
--------------------------------------------------------------------------------------
[CredentialProvider]DeviceFlow: https://mytools.pkgs.visualstudio.com/MyBot/_packaging/MyTools/nuget/v3/index.json
[CredentialProvider]ATTENTION: User interaction required.
**********************************************************************
To sign in, use a web browser to open the page https://microsoft.com/devicelogin to authenticate.
**********************************************************************
C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error : [CredentialProvider]Device flow authentication failed. User was presented with device flow, but didn't react within 90 seconds. [C:\Users\VssAdministrator\AppData\Local\Temp\wk4fkuq1.hqu\restore.csproj]
C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error : Unable to load the service index for source https://mytools.pkgs.visualstudio.com/MyBot/_packaging/MyTools/nuget/v3/index.json. [C:\Users\VssAdministrator\AppData\Local\Temp\wk4fkuq1.hqu\restore.csproj]
C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\VssAdministrator\AppData\Local\Temp\wk4fkuq1.hqu\restore.csproj]
Restore completed in 775.06 ms.
Tool 'dotnet-ef' (version '3.1.1') was restored. Available commands: dotnet-ef
Package "localenv" failed to restore, due to Microsoft.DotNet.ToolPackage.ToolPackageException: The tool package could not be restored.
at Microsoft.DotNet.Tools.Tool.Install.ProjectRestorer.Restore(FilePath project, PackageLocation packageLocation, String verbosity)
at Microsoft.DotNet.ToolPackage.ToolPackageInstaller.InstallPackageToExternalManagedLocation(PackageLocation packageLocation, PackageId packageId, VersionRange versionRange, String targetFramework, String verbosity)
at Microsoft.DotNet.Tools.Tool.Restore.ToolRestoreCommand.InstallPackages(ToolManifestPackage package, Nullable`1 configFile)
Restore partially failed.
##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x SDK/Runtime along with 2.2 & 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions.
Some commonly encountered changes are:
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects :
##[section]Finishing: Restore tools! (Including efcore tools)
Fail to execute “dotnet tool restore --interactive” in Build Pipeline when using Azure DevOps Artifact
You could not use the command line dotnet tool restore --interactive on the hosted agent, that because:
Microsoft decided not to put the plugin artifacts-credprovider in dotnet.exe because there
were concerns that shipping auth integration to Azure DevOps within
the sdk would've been unfair to other feed providers. To resolve your
401 issues you need to install the auth plugin manually.
That the reason why you get the 401 (Unauthorized) error.
In addition, you mentioned that you do not want to commit the token info in the nuget.config file, as a solution for this issue, you could add a nuget Service connections with PAT:
Then use this externalFeedCredentials: nugettest in the dotnet restore task instead of powershell task (there is no option to accept the certification Information):
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: path/to/xxx.csproj
feedsToUse: config
nugetConfigPath: path/to/NuGet.Config
externalFeedCredentials: nugettest
Then we could resoter the package from our private feed.
If you get the 403 403 (Forbidden) error with above method, you can check the thread here.
Hope this helps.
You can't use the flag --interactive in a build pipeline, because this flag except to get an output from the user during the execution.
You can use the default restore option in the .Net core task:
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '$(Build.SourcesDirecotry)/path/to/csproj'
feedToUse: 'config'
nugetConfigPath: '$(Build.SourcesDirectory)/path/to/nuget.config'
This one is because you should let agent know the nuget sources with pre-authenticated feed url prior to dotnet restore:
- task: NuGetCommand#2
displayName: 'Add Nuget Feed'
inputs:
command: custom
arguments: 'sources add -name <name_of_source> -source <feed_url>'
I hope this would be useful.

Deploying .NET Core 3.0 API to Azure Web App using Release Pipeline

I'm attempting to upgrade my API from .NET Core 2.2 to 3.0, but I cannot get the Azure Web App to actually run the application using 3.0.
My build pipeline configuration:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core 3'
inputs:
version: 3.x
- script: dotnet tool install --global dotnet-ef
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: efcore-migration-script-generator-task#0
inputs:
projectpath: 'Models/Models.csproj'
databasecontexts: 'DataContext'
startupprojectpath: 'Api/Api.csproj'
targetfolder: '$(build.artifactstagingdirectory)/migrations'
- script: dotnet publish --output $(Build.ArtifactStagingDirectory)
displayName: 'dotnet publish $(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
I then have a multi-stage release pipeline that publishes the artifact to Azure using the Azure App Service Deploy Task. Everything runs without issue
I've installed the preview extension, as directed here, and running the powershell command Test-Path D:\home\SiteExtensions\AspNetCoreRuntime.3.0.x86\ returns true. I'm still seeing the following error though.
ANCM Failed to Find Native Dependencies
Back in Powershell, running dotnet --version and dotnet --list-runtimes shows that it only recognizes .NET Core 2 runtimes, despite the 3.0 runtime being present. As best I can tell, installing the site extension doesn't update the path to use the new dotnet version, and the Azure Devops deploy task doesn't seem to have any options to override the default. Has anyone managed to get a .NET Core 3 app deployed through Azure Devops Release Pipelines?
I don't consider it a good solution by any means, but the workaround I'm using right now that is working is to add a web.config file that passes the full path to the site extension version of dotnet
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="D:\home\SiteExtensions\AspNetCoreRuntime.3.0.x86\dotnet" arguments=".\Api.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
I'm still looking for a solution that isn't so error prone.

How to create a YAML build pipeline in azure devops for xamarin projects with referenced dot net projects

I recently moved my sources to azure devOps to use cd/ci and all the other cool stuff.
Now i created my first build pipeline to build the android part of my Xamarin project. But I end up getting an error message, that a resource of a referenced project could not be found and i shall do a package restore and try again.
Now, since i have azure hosted build agents and not self hosted, i have no ways of setting the agent up properly before doing the build.
But i guess there should be some way to properly configure the build pipeline to do all the necessary stuff.
Its just that i have no clue what i should add to my yaml file in order to fix this stuff.
This is the error message i got:
##[error]C:\Program Files\dotnet\sdk\2.2.105\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208,5): Error NETSDK1004: Assets file 'd:\a\1\s\*****\*****\*****\*****\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.
The problem is, that this file should be generated by compiling a referenced project and is not part of a nuget package.
Here is my build pipeline as far as i figured it out by myself.
# Xamarin.Android
# Build a Xamarin.Android project.
# Add steps that test, sign, and distribute an app, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/xamarin
trigger:
- Share/main
pool:
vmImage: 'VS2017-Win2016'
variables:
buildConfiguration: 'Debug'
outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)'
steps:
- task: NuGetToolInstaller#1
inputs:
versionSpec: 5.1.0
- task: NuGetCommand#2
displayName: 'Restore NuGet Packages'
inputs:
command: restore
restoreSolution: '**/*.sln'
- task: XamarinAndroid#1
inputs:
projectFile: 'Mobile4/Droid/Mobile4.Droid.csproj'
outputDirectory: '$(outputDirectory)'
configuration: '$(buildConfiguration)'
- task: AndroidSigning#3
inputs:
apksign: false
zipalign: false
apkFiles: '$(outputDirectory)/*.apk'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(outputDirectory)'
The build always breaks on step XamarinAndroid
I hope you can help me.
The solution must be out there somewhere, i just cannot see it right now.
Thx in Advance.
Mav
[error]C:\Program Files\dotnet\sdk\2.2.105\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208,5):
Error NETSDK1004: Assets file
'd:\a\1\s********************\obj\project.assets.json' not found.
Run a NuGet package restore to generate this file.
According to this error message, the project is .NetCore and its SDK used is 2.2.105. For the file "....\obj\project.assets.json", whether the project.assets.json exists is determined by package restore step. Now, it prompt this could not be found, it means the package restore does not restore this file successfully.
As I mentioned previously, it is a .NetCore project. So you should use dotnet restore instead of nuget restore. For .NetCore project, the obj folder restored by nuget restore does not contain project.assets.json in it.
So, to solve the issue you meet, you should replace the task Nuget restore as dotnet restore: dotnet.
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/*.csproj'
vstsFeed: 'e157d03d-******-fc06f9e13177'

Resources