AzureDevops Task name NuGetCommand is ambiguous - azure

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

Related

.Net Core Seleniun Tests in Azure DevOps- No Files matched the search pattern error for .Net restore task

Created a .Net core Selenium tests in Azure Repos.
I have the .csproj as well in the Repos.
Added a ASP.Net core task, in the restore task i have given Path to Project as "**/*.csproj".
Got the below error while running the build pipeline.
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
##[error]No files matched the search pattern
Not sure if the Agent didnt find my .csproj file. Any help is deeply appreciated.
I tried to reproduce your issue, but the task ran successfully.
My environment:
Agent: ubuntu-latest
.Net SDK Version: 3.1.403
My script:
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'select'
You can do the following things to locate your issue:
Rerun the pipeline using my environment configuration.
Write the full and detailed path name. For example, $(System.defaultWorkingDirectory)/WindowsApp.csproj.
Add a command line task to run dotnet restore directly.
Set the system.debug variable to true. Rerun your pipeline and you will see a more detailed run log.

Azure pipeline task DotNetCoreCLI#2 - output folder of artifact

In our .NET Web API project, we tried to build API project in Azure DevOps and publish the artifact to a folder with the pipeline task below:
- task: DotNetCoreCLI#2
displayName: Publish web API artifact
inputs:
command: publish
publishWebProjects: false
arguments: '$(Build.SourcesDirectory)\XYZ.Research.API\XYZ.Research.API.csproj --configuration $(BuildConfiguration) --output testpath'
zipAfterPublish: true
modifyOutputPath: true
But I am not sure which folder the artifact is kept. Below is the log from this step:
2020-07-31T12:04:23.6282186Z ##[section]Starting: Publish web API artifact
2020-07-31T12:04:23.6590490Z ==============================================================================
2020-07-31T12:04:23.6591051Z Task : .NET Core
2020-07-31T12:04:23.6591393Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2020-07-31T12:04:23.6591740Z Version : 2.172.2
2020-07-31T12:04:23.6591974Z Author : Microsoft Corporation
2020-07-31T12:04:23.6592357Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2020-07-31T12:04:23.6592942Z ==============================================================================
2020-07-31T12:04:25.5581194Z [command]C:\windows\system32\chcp.com 65001
2020-07-31T12:04:25.5581889Z Active code page: 65001
2020-07-31T12:04:25.5583746Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
2020-07-31T12:04:25.5588792Z [command]C:\hostedtoolcache\windows\dotnet\dotnet.exe publish d:\a\1\s\XYZ.Research.API\XYZ.Research.API.csproj --configuration Release --output testpath
.....
some warning message ignored
.....
2020-07-31T12:04:38.0843543Z XYZ.Research.API -> d:\a\1\s\XYZ.Research.API\bin\Release\netcoreapp3.0\XYZ.Research.API.dll
2020-07-31T12:04:38.9127845Z XYZ.Research.API -> d:\a\1\s\testpath\
2020-07-31T12:04:46.0295716Z Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.1) SDK/Runtime along with 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.
2020-07-31T12:04:46.0296632Z Some commonly encountered changes are:
2020-07-31T12:04:46.0297619Z 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
2020-07-31T12:04:46.0442329Z ##[section]Finishing: Publish web API artifact
Because we will need the file location in next step (deployment), I tried
d:\a\1\s\testpath\XYZ.Reserch.API.zip
d:\a\1\s\testpath\XYZ.Reserch.API\XYZ.Reserch.API.zip
but none of these location has the artifact file.
Did anyone see this issue before? Any help would be appreciated.
------------------- update -------------------------------
As #Source Code suggested, I used task "PowerShell#2" and find that the artifact file are actually in "D:\a\1\s\testpath\testpath.zip". That means the 'testpath' sub-folder are created in $(Build.SourceDirectory) and the artifact file are also renamed to 'test.zip'.
I would recommend that you add a PowerShell/Bash/Cmd task after your DotNetCoreCLI#2 task and run a inline script with the 'ls' command that should list all the items to the results for you. This will allow you to see what is actually there after the task.
If on a Windows agent:
- task: PowerShell#2
displayName: List Files Post Publish
inputs:
targetType: inline
script: Get-ChildItem
If on Linux or Mac
- task: Bash#3
displayName: List Files Post Publish
inputs:
targetType: inline
script: ls
Additionally I noticed you're providing your csproj file via the arguments parameter. There is a parameter named projects which should be used for this. Also you may consider using the the artifacts staging directory as your output directory. The task would look like this:
- task: DotNetCoreCLI#2
displayName: Publish web API artifact
inputs:
command: publish
projects: '$(Build.SourcesDirectory)\XYZ.Research.API\XYZ.Research.API.csproj'
publishWebProjects: false
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
modifyOutputPath: true
One important thing to note is if you do change the output directory ensure that you change the working directory for the PowerShell or Bash tasks so you output the contents of the correct directory. It defaults to the $(Build.SourcesDirectory) so ensure that you change this if needed.

Dependencies getting copied to private feed in Azure DevOps

I have set up a build pipeline for a model library that's shared between several of my projects. I'm accessing it through a private feed in Azure DevOps, and it works just fine. I can retrieve the library in Visual Studio and my projects all get the most up-to-date version. However, in the feed are all the dependency libraries used within the model library (e.g. Microsoft.Azure.Storage.Blob, System.Threading, Microsoft.AspNetCore, etc.). I haven't been able to find any guidance on why this is happening, if it's the expected behavior, or if I'm screwing something up. My YAML file for the build pipeline is below:
Also, does anyone know a better to handle package versioning? This seems really hacky, but it was the only way I could get auto-incrementing versions to work.
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
name: $(projectName)-$(majorMinorVersion).$(semanticVersion)
pool:
vmImage: 'windows-latest'
# pipeline variables
variables:
majorMinorVersion: 1.1
# semanticVersion counter is automatically incremented by one in each execution of pipeline
# second parameter is seed value to reset to every time the referenced majorMinorVersion is changed
semanticVersion: $[counter(variables['majorMinorVersion'], 0)]
projectName: 'MyProject.Models'
buildConfiguration: 'Release'
projectPath: 'Shared/MyProject.Models.csproj'
fullVersion: '$(majorMinorVersion).$(semanticVersion)'
steps:
# show version number on start
- task: Bash#3
inputs:
targetType: 'inline'
script: |
echo Building $(projectName)-$(fullVersion)
- task: DotNetCoreCLI#2
inputs:
command: 'pack'
packagesToPack: $(projectPath)
versioningScheme: 'byEnvVar'
versionEnvVar: 'fullVersion'
- task: DotNetCoreCLI#2
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/MyProject.Models*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: '<feed GUID>'
Dependencies getting copied to private feed in Azure DevOps
That because your private Nuget Feed set nuget.org as an Upstream source by default if you set Package from public sources enable when you create the this feed:
Then go to Setting->Upstream source, you will find there are three public sources listed:
When we download any packages from the Upstream sources, it will been cached in the Artifacts, you will see it next time. They are cached packages from upstream sources, so we do not need to download them again from upstream sources next time we use them, and the included upstream sources are all approved by MS, so you do not need to worry about them.
Besides, if you still worry about them, you can disable the Upstream sources, but in this case, you need publish all the dependencies to your private feed, otherwise, your model library package will throw the error could not found the dependencies.
Hope this helps.

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.

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