AzureDevOps doesn't restore packages from AzureDevOps feed - nuget

Using AzureDevOps I should be able to restore packages from the feeds hosted within AzureDevOps.
The Nuget.config seems correct, the build has access to the feed, locally it runs fine with explicitly using the same config file.
I've seen VSTS Build vNext NuGet custom package source but would very much like to stay out of adding apikey's there. The official documentation states it should be possible: https://www.visualstudio.com/docs/package/get-started/build/team-build
NuGet.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Net2Library" value="https://xxx.pkgs.visualstudio.com/DefaultCollection/_packaging/yyy/nuget/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
Feed settings
Restore settings (it uses the correct config, visible from listing the feed in the logs)
Relevant logs:
2016-07-30T12:33:37.8085538Z Restoring NuGet package XYZ.2016.7.29.14.
2016-07-30T12:33:42.6885539Z Unable to find version '2016.7.29.14' of package 'XYZ'.
2016-07-30T12:33:42.6915543Z Feeds used:
2016-07-30T12:33:42.6925542Z C:\Users\buildguest\AppData\Local\NuGet\Cache
2016-07-30T12:33:42.6925542Z C:\Users\buildguest\.nuget\packages\
2016-07-30T12:33:42.6925542Z https://api.nuget.org/v3/index.json
2016-07-30T12:33:42.6935552Z https://xxx.pkgs.visualstudio.com/DefaultCollection/_packaging/yyy/nuget/v3/index.json
2016-07-30T12:33:42.7235541Z ##[debug]rc:1
2016-07-30T12:33:42.7245545Z ##[debug]success:false
2016-07-30T12:33:42.7325527Z ##[error]Error: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.103.1\agent\Worker\Tools\nuget.exe failed with return code: 1
2016-07-30T12:33:42.7335525Z ##[error]Packages failed to install
2016-07-30T12:33:42.7335525Z ##[debug]task result: Failed
2016-07-30T12:33:42.7345538Z ##[error]Return code: 1

This is caused by VSTS issue which has been fixed by now, please try the build again.
Issue: Failures while restoring nuget packages in Visual Studio Team Services – 8/1 – Resolved
Other possible issue: Packaging issues with Visual Studio Team Services – 7/30 – Resolved
.

I'm having the exact same issue. I've been experiencing the error most of the times when the build starts from a push from the local repo (either from VS 2015 or git bash). The workaround for me has been to queue a build directly on VSTS build definition, through "Queue Build.It's annoying but it's the only way I found to overcome the issue. I do think this is a bug and hope MS fix it. Hope my workaround helps.

Related

nuget local feed stops working when package with two different versions is present

I am trying to use nuget local feed for publishing my packages. So, I tried to push my first component / package. I have the following nuget.config in my sdk project:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="local feed" value="x:\nuget\packages\" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
<packageManagement>
<add key="format" value="0" />
<add key="disabled" value="False" />
</packageManagement>
</configuration>
SDK Project's configuration is as follows:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Title>My custom component</Title>
<Version>0.0.1-alpha</Version>
<PackageId>$(RootNamespace)</PackageId>
</PropertyGroup>
I set the project to Release configuration, and execute Pack command. As a result, .nupkg file is created in bin/Release folder.
Inside the package manager console window, I execute the following command:
nuget add pathToNupkgFile -Source x:\nuget\packages
So far so good, package is located in folder x:\nuget\packages\companyname.components.blazor.mycomponent\0.0.1-alpha.
Now I created new solution where I want to consume package from local feed. I copied the same nuget.config file to folder where new solution was created. I open Manage Nuget Packages for Solution (short MNPfS), search for new package, and install it. All fine until this point.
Now, if I do the same procedure and create 0.0.2-alpha nupkg, after nuget add command, new version is present in x:\nuget...., but I am unable to browse local feed any more in MNPfS screen. As soon as I open MNPfS, I get following message in window where packages should be listed:
Error occured
And error list window displays following message:
Error [local feed] '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1.
Now, if I delete version 0.0.1-alpha from local feed repository, then I can browse again in MNPfS and new package is displayed, and can be installed. So, the problem occurs only when two versions of same package are present.
Anyone knows why is this happening, and how can I have multiple versions of same package in local feed?
Looks like the problem was related to nuget add command -Source parameter. When source points to partition with FUSE file system, then it does not create proper nuspec file, although no error is provided in Package Manager console.
nuspec file results in content with multiple NULL values. If I specify -Source to current partition where project is, then nuspec file is properly created, and then I can just copy the content to FUSE file system, and all works OK.

How to Install Azure Artifacts Packages dependencies in Vs Code?

How to Install the Azure Artifacts Packages in VS Code, I tried to check the Connect to feed option and found there are multiple Nuget options like Dotnet, Nuget.exe, and Visual Studio, etc.
But when I am trying for VS Code then it's not working.
What I did so far in the VS Code?
1 Approach) I install the NuGet package manager and when I am trying to do search my package then it's not showing in the list. but using this command "Get-PackageSource" I am able to see the package in the console.
2 Approach) I created one nuget.config file and mentioned below the package details
'<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="test#Release" value="https://xxxxxxx.pkgs.visualstudio.com/_packaging/test/nuget/v3/index.json" />
</packageSources>
</configuration>'
after that running NuGet restore command and below giving the output but I didn't see any dependencies in the project and the same thing working fine using Visual Studio 2017
NuGet Config files used:
C:\Users\sudhir\source\repos\testPrivateNugetFeed\NuGet.Config
C:\Users\sudhir\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
C:\Program Files (x86)\NuGet\Config\Xamarin.Offline.config
Feeds used:
`https://XXXXX.pkgs.visualstudio.com/_packaging/test/nuget/v3/index.json'
All projects are up-to-date for restore.
I have also followed this thread
Add custom package source to Visual Studio Code
Please give me some solution.
How to Install Azure Artifacts Packages dependencies in Vs Code?
I could reproduce this issue on my side, it seems to be a limitation of the NuGet package manager extension or Visual Studio Code.
No matter how I set up my Nuget.config file, I could not see the custom nuget package from the Azure devops feed in the NuGet package manager extension. I also test any other extension like NuGet Gallery, but not success.
To resolve this issue, I add following nuget.config file in my project, which next to my .sln file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AzureDevOpsFeed" value="https://pkgs.dev.azure.com/<MyORGName>/_packaging/<MyFeedName>/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<config>
</config>
<packageSourceCredentials>
<AzureDevOpsFeed>
<add key="Username" value="LeoTest" />
<add key="ClearTextPassword" value="My PAT Here" />
</AzureDevOpsFeed>
</packageSourceCredentials>
</configuration>
And add following in my packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LibA" version="1.0.0" targetFramework="net461" />
</packages>
The LibA is a custom package in my Azure decops feed:
Then I use nuget.exe to restore the package for my project:
If nuget restore not work for you, please share the log for that command.

Devops using packages from private Azure Artifacts feed: unexpected status code '404 Not Found'

My solution contains references to some private Nuget packages in a feed hosted in a Devops Artifact.
It builds on my machine.
However the Dev ops build fails because I need to set up access to the private Nuget Feed.
I am studying the docs
I have a nuget.config file in my solution with a reference to my private feed.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<activePackageSource>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</activePackageSource>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="MyFeed" value="myfeed/nuget/v3/index.js" />
<!-- Others -->
</packageSources>
<packageSourceCredentials>
<!-- secret stuff -->
</packageSourceCredentials>
</configuration>
The NugetCommand task has an error (edited)
NU1000: Unable to find version 'myversion' of package 'MyPackageName'.
C:\Users\VssAdministrator\.nuget\packages\: Package 'MyPackageName-Version' is not found on source 'C:\Users\VssAdministrator\.nuget\packages\'.
The build pipeline has a task
- task: NuGetCommand#2
inputs:
restoreSolution: '**\*.sln'
feedsToUse: config
nugetConfigPath: 'myproject/nuget.config'
The edited error is
NU1000: Unable to find version 'myversion' of package 'mypackage'.
C:\Users\VssAdministrator\.nuget\packages\: Package 'mypackage-versionumber' is not found on source 'C:\Users\VssAdministrator\.nuget\packages\'.
myfeed/nuget/v3/index.js: The V2 feed at 'myfeed/nuget/v3/index.js/FindPackagesById()?id='mypackage'&semVerLevel=2.0.0' returned an unexpected status code '404 Not Found'.
https://api.nuget.org/v3/index.json: Package 'mypackage' is not found on source 'https://api.nuget.org/v3/index.json'.
Why would the error mention a V2 feed?
In VS2017 15.9.7 Help About, I see that NuGet Package Manager is 4.6.0
I wonder if it could be an access issue.
In Devops the project containing the package feed is in the same organisation as the consuming project.
Configure Devops to use packages from private Azure Artifacts feed
Your YAML file and configuration steps are correct. I test it on my side and it works fine, but I found that your private Nuget packages feed path does not seem to be incorrect, so confirm with you by comments.
The path should be .json file. We could copy it from Azure Artifacts feed with connect to feed button:
Post it as answer, hope it would be helpful to anyone who encounters similar issues.
Thanks also to the confirmation of #Kirsten Greed.

Mixing packages from nuget.org and repository folder in VSTS

My solution grabs some nuget packages from Nuget.org and some of them are in my repository under the "lib" folder. I am aware that having packages in my repository is not the best option, but for now, i am stuck with it.
In my solution nuget.config looks like this :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="CustomSource" value="../lib" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
It works fine in Visual Studio.
In VSTS I changed the nuget restore task option :
My build fails like this:
The nuget command failed with exit code(1) and error(Failed to
retrieve information about
'Microsoft.Extensions.Configuration.Abstractions' from remote source
'D:\a\1\lib'.)
Packages failed to restore
Obviously, Microsoft.Extensions.Configuration.Abstractions, is supposed to download from nuget.org. What should I change so it tries to use the 2 nuget sources?
Thanks!
If you specify your own NuGet.config file in NuGet restore task, it will save the content of the specify NuGet.config file to a temporary config file like: D:\a\1\Nuget\tempNuGet_3274.config.
So If you are using Hosted agent, you should specify the local feed path as:
<add key="CustomSource" value="../s/Projectname/lib" />
Besides, you can also use private agent which locate in your local machine, so that the packages can be found from other directory.

Using NUnit and Nuget with Bamboo Cloud

I'm trying to create a plan on Bamboo Cloud (not Bamboo Server) for a .Net project:
Check out from Bitbucket
Nuget to get all package
MSBuild to compile the solution
NUnit to run the unit tests
1) and 3) is easy, but I can't figure out how to create tasks that run Nuget and NUnit. It seems you first have to install the executables on the build agent. I found documentation on how to do this for Linux, but not for Windows.
How do I create Nuget and NUnit tasks with Bamboo Cloud?
I did this by splitting up my Job into 4 tasks:
Source Code Checkout
As you would expect. It's the default task within a job anyway.
Download NuGet.exe
A one-liner Powershell inline script with
Invoke-WebRequest -Uri 'http://nuget.org/nuget.exe' -OutFile '.\nuget.exe'
Download all package dependencies via NuGet
This approach now seems to be the "new" recommended approach, so it's a simple CMD file that executes
nuget.exe restore
MSBuild
Using the .SLN file as parameter for the Project File option in the task and passing any needed other msbuild options in the Options field
My Bamboo server is on Linux and my remote agent is on the Windows build machine.
In your case you would follow up with the 5. task, e.g. the Nunit tests - though you may decided to put that into a separate stage, and split the tests into jobs that can run in parallel.
Edit: almost forgot: I also have a Nuget.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="Syncfusion" value="http://nuget.syncfusion.com/xamarin/" />
</packageSources>
<!-- Used to specify which one of the sources are active -->
<activePackageSource>
<!-- this tells only one given source is active -->
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<!-- this tells that all of them are active -->
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>