Azure CI using alternative nuget feed - c#

I'm trying to get Azure to check an alternative nuget feed for packages as well as the default one.
I have configured my CI to auto deploy to an azure webapp when i check into source control.
My solution uses a few nuget packages which are currently only on the Azure nightly feed. I've changed my nuget.targets file as below to include both the nightlies feed and the default nuget feed.
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<PackageSource Include="http://www.myget.org/F/azure-appservice/api/v2/" />
<PackageSource Include="https://api.nuget.org/v3/index.json" />
</ItemGroup>
However when I checkin it fails, and looking at the Activity Logs in Azure I can see that it has failed to find the nightly packages as it's not looking in the the http://www.myget.org/F/azure-appservice/api/v2/ feed
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin'.
Feeds used:
C:\DWASFiles\Sites\#1<REDACTED>__43ae\LocalAppData\NuGet\Cache
D:\local\UserProfile\.nuget\packages\
https://api.nuget.org/v3/index.json
Restoring NuGet package Microsoft.Azure.WebJobs.1.1.2-alpha-10245.
Restoring NuGet package Microsoft.Azure.WebJobs.Extensions.1.0.2-alpha-10232.
Restoring NuGet package Microsoft.Azure.WebJobs.Core.1.1.2-alpha-10245.
WARNING: Unable to find version '1.0.2-alpha-10232' of package 'Microsoft.Azure.WebJobs.Extensions'.
WARNING: Unable to find version '1.1.2-alpha-10245' of package 'Microsoft.Azure.WebJobs'.
WARNING: Unable to find version '1.1.2-alpha-10245' of package 'Microsoft.Azure.WebJobs.Core'.
Restoring NuGet package Microsoft.Azure.WebJobs.Extensions.SendGrid.1.0.2-alpha-10232.
WARNING: Unable to find version '1.0.2-alpha-10232' of package 'Microsoft.Azure.WebJobs.Extensions.SendGrid'.
Unable to find version '1.0.2-alpha-10232' of package 'Microsoft.Azure.WebJobs.Extensions.SendGrid'.
Unable to find version '1.1.2-alpha-10245' of package 'Microsoft.Azure.WebJobs.Core'.
Unable to find version '1.1.2-alpha-10245' of package 'Microsoft.Azure.WebJobs'.
Unable to find version '1.0.2-alpha-10232' of package 'Microsoft.Azure.WebJobs.Extensions'.
Failed exitCode=1, command=nuget restore "D:\home\site\repository\<REDACTED>.sln"
An error has occurred during web site deployment.
Unable to find version '1.0.2-alpha-10232' of package 'Microsoft.Azure.WebJobs.Extensions.SendGrid'.\r\nUnable to find version '1.1.2-alpha-10245' of package 'Microsoft.Azure.WebJobs.Core'.\r\nUnable to find version '1.1.2-alpha-10245' of package 'Microsoft.Azure.WebJobs'.\r\nUnable to find version '1.0.2-alpha-10232' of package 'Microsoft.Azure.WebJobs.Extensions'.\r\nC:\Program Files (x86)\SiteExtensions\Kudu\52.50316.2137\bin\scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
Does anyone know how to configure this?

As per matthews reply https://github.com/Azure/azure-webjobs-sdk/issues/663
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<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://www.nuget.org/api/v2/" />
<add key="azure_app_service" value="https://www.myget.org/F/azure-appservice/api/v2" />
<!--<add key="buildTools" value="https://www.myget.org/F/30de4ee06dd54956a82013fa17a3accb/" />-->
</packageSources>
</configuration>

Related

NuGet package is not being installed when reading from TFS

We are using Visual Studio 2019 and we have a solution that has a references to some NuGet packages either from nuget.org or from our private server we are managing the solution with packages.config management, the problem is there is one ASP.NET project in that solution that does not install any of the required packages(in our case it misses the NewtonSoft.json), and installs all the other ones correctly, even though we have packages restore enabled, and there are other ASP.Net projects in the solution that install the Newtonsoft package correctly, but each time you read the last version of the solution from zero (in the case you delete the local solution and re-read it) from the TFS, you need to install the Newtonsoft.json manually for that project specifically.
PS: it's a problem that can be solved in 5 min every time but I know something is wrong and I have been trying to understand what is it, I don't want to solve it localy, but I need a solution the resolve it on the TFS level, so please help me if you can or if you know any other questions here that can help, please guide me through (if I didn't see it already).
My NuGet.Config document:
<?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="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="MxNuget" value="our server path" />
</packageSources>
<activePackageSource>
<add key="All"
value="(Aggregate source)" />
</activePackageSource>
<packageRestore>
<add key="enabled" value="true" />
<add key="automatic" value="true" />
</packageRestore>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
the error we are getting is the following:
The name 'Newtonsoft' does not exist in the current context.
The problem I was having was because the TFS was not restoring all the packages needed because when he sees the Folder 'Packages' in the solution he just check if the package is inside, and when he is done, the version that he found and the one on the local machine may be different and that was causing the problem, so I wanted to delete my packages folder on the TFS but I couldn't find it. For that I installed a package in my solution which adds .tfignore to the .nuget folder in the solution directory, and that last file tells the TFS to ignore the packages file on the server and restor them always.
Questions that were useful:
1 - Tfs Can't restore Nuget packages.
2- NuGet Packages are missing
3- External: Missing Nuget Packages on TFS Build Server
I resolved the problem by following the steps:
installed the package DisableSourceControlIntegration to the project that was missing the Newtonsoft.json NuGet.
Unified all the versions of NewtonSoft.json on the projects to which my ASP.Net project has a reference. (I think that was the main problem because I had them unified before but I updated the whole group with their config files).
In the visual studio, open Tools --> Nuget package manager --> package manager setting and make sure that the Packages.config is selected as the format of managing the NuGet packages.
deleted all the packages cash.
Re-compiled the solution.
Pushed to the TFS.

Azure Devops build not restoring automapper nuget

I am trying to build a .Net project but it doesn't find Automapper v3.3.1.
I have the following build steps:
Use NuGet 4.3.0
NuGet restore
Build solution ...
When running step 3 it gives the error:
Error CS0246: The type or namespace name 'AutoMapper' could not be
found (are you missing a using directive or an assembly reference?)
In the Nuget Restore step I have the
Path to solution, packages.config, or project.json set to the .sln file.
Under Feeds and authentication I checked the option Feeds and in my NuGet.config I left path to NuGet.config empty since I have a global Nuget.config file on the build server under:
C:\Users\user\AppData\Roaming\NuGet\NuGet.config
In this file I have the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<AzureDevOpsFeed>
<add key="Username" value="MyUsername" />
<add key="PAT" value="MyPatKey" />
</AzureDevOpsFeed>
</configuration>
I would assume the build would use the package source https://api.nuget.org/v3/index.json to restore Automapper.
Any idea why this is not working?
The solution quoated from
NuGet not restoring packages on build
I had to go into Source Control and delete all of the files in the
packages folder (except repositories.config) before NuGet would
restore the missing packages. The idea is that you are using package
restore rather than checking your packages in to source control. If it
sees the packages in source control, it won't download them.
I had same problem. Try to delete nuget packages folder and rebuild the solution.

VSTS unable to load the service index for source 401

I'm aware of the other posts about the same signature. I still can't resolve my issue after going thru them.
My team uses VSTS's build definition for continuous integration.
This build definition works fine until the lastes pull request.
I'm running into the error msg below during the Nuget Restore
2018-06-20T00:37:27.6438127Z System.AggregateException: One or more errors occurred. ---> NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://microsoft.pkgs.visualstudio.com/_packaging/CBT/nuget/v3/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
I do have https://microsoft.pkgs.visualstudio.com/_packaging/CBT/nuget/v3/index.json in the nuget.config, and there is nothing changed in the nuget.config in the failing PR
I can nuget restore and build the entire solution successfully on my local machine using VS2017. The only related change in the PR is that instead of using package.config, it uses packagereference to get the nuget package. I tried to move back to using package.config, the build would still fail with the same error msg.
Thanks in advance.
You can update the VSTS feed with credentail (PAT or alternate credential) in the specified nuget.config file.
Such as:
nuget sources update -Name "vstsfeed" -Source https://microsoft.pkgs.visualstudio.com/_packaging/CBT/nuget/v3/index.json -Username "Alternate username" -Password "alternate password" -configfile /path/to/nuget.config
Then you can commit the changes for the nuget.config file and push to VSTS repo. And build again to check if it works.
You can use a command as shown in the accepted answer - also, you can add the feed in a nuget.config file placed in the root of your repo
Notice, this shows how to add credentials for a custom feed with spaces in the feed name: My Nuget Artifacts
<?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 official package source" value="https://api.nuget.org/v3/index.json" />
<add key="My Nuget Artifacts" value="https://pkgs.dev.azure.com/ConsotoOrg/_packaging/Consoto/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<My_x0020_NuGet_x0020_Artifacts>
<add key="Username" value="justme" />
<add key="ClearTextPassword" value="xyzyoqyvslyfs1t1khru6wd33gebujhpr9moocbujfhv8ukxtxyz" />
</My_x0020_NuGet_x0020_Artifacts>
</packageSourceCredentials>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<!--
Used to specify trusted signers to allow during signature verification.
See: nuget.exe help trusted-signers
-->
<trustedSigners>
<author name="microsoft">
<certificate fingerprint="3F9001EA83C560D712C24CF213C3D312CB3BFF51EE89435D3430BD06B5D0EECE" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
</author>
<repository name="nuget.org" serviceIndex="https://api.nuget.org/v3/index.json">
<certificate fingerprint="0E5F38F57DC1BCC806D8494F4F90FBCEDD988B46760709CBEEC6F4219AA6157D" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
<owners>microsoft;aspnet;nuget</owners>
</repository>
</trustedSigners>
</configuration>
FWIW - In recent days, I've found I can clear up some NuGet restore errors by removing the trustedSigners section from the config
This is not what the problem was with the OP but I'm adding a note here since I found this question while searching for the same error message.
In our case we were building a .net 5 app for in Azure DevOps. We had to upgrade to a newer version of NuGet using the NuGet tool installer. Then the restore worked just fine using the .Net Core task with the restore command.

Nuget returned an unexpected status code '404 Not Found' - Package on local drive

Trying to generate a Nuget Package from dll. One of our project is generating ConfigurationCore.dll and References of project assemblies given below
Microsoft.CSharp
Newtonsoft.Json
Mak.Enums (Custom Nuget Package available on local Nuget Server)
Mak.Operations (Custom Nuget Package available on local Nuget Server)
PresentationCore, PresentationFramework, PresentationFramework.Aero
System, System.Core, System.Data, System.Data.DataSetExtensions
System.Drawing, System.IO.Compression, System.IO.Compression.FileSystem
System.Net.Http, System.Runtime.Serialization, System.Web
System.Xaml, System.Xml, System.Xml.Linq, WindowsBase
Using below ConfigurationCore.nuspec to generate Nuget Package
<?xml version="1.0"?>
<package >
<metadata>
<id>ConfigurationCore</id>
<version>1.2.0</version>
<title>Configuration Core</title>
<authors>MAKK</authors>
<owners>IT Department</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ConfigurationCore contains core funcationality of Software</description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2018</copyright>
<dependencies>
<dependency id="Newtonsoft.Json" version="10.0.3" />
</dependencies>
</metadata>
<files>
<file src="C:\Users\makk\source\repos\ConfigurationCore\bin\x86\Test\ConfigurationCore.dll" target="lib\net461" />
</files>
</package>
Attempting to gather dependency information for package 'ConfigurationCore.1.2.0' with respect to project 'NugetTest', targeting '.NETFramework,Version=v4.6.1'
Gathering dependency information took 1.09 sec
Attempting to resolve dependencies for package 'ConfigurationCore.1.2.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'ConfigurationCore.1.2.0'
Resolved actions to install package 'ConfigurationCore.1.2.0'
The V2 feed at 'http://builtsrv1:8080/nuget/FindPackagesById()?id='ConfigurationCore'&semVerLevel=2.0.0' returned an unexpected status code '404 Not Found'.
Time Elapsed: 00:00:02.1513344
========== Finished ==========
Note: The Nuget package source is on local harddrive... Please advise to fix the issue.
Update your Nuget package link.
Go to Project -> Manage Nuget Packages.
Now click on your package source settings.
Update Source Link to https://api.nuget.org/v3/index.json
Your URL should end with /nuget
Example:
http://yourDomain.co/yourNuGetServer/nuget
This is problem of bad connection in the NuGet package. Add the following link into the NuGet Package.
https://api.nuget.org/v3/index.json
Tha
Nuget returned an unexpected status code '404 Not Found' - Package on local drive
Make sure the path in the src="..." is correct.
Perhaps the path should be:
...\ConfigurationCore\ConfigurationCore\... rather than ...\ConfigurationCore\....
In short, make sure you can find the dll file base on that url.
Note: Generally, we recommend using relative paths in url, like:
<file src="bin\x86\Test\ConfigurationCore.dll" target="lib\net461" />
Update the version of nuget.exe.
There is an issue on the nuget.exe 3.4.x, so please download nuget.exe 3.5 and above.
See Create nuget package from dlls for more detailed info.
Update:
Please following below steps to create the nuget package:
Download the nuget.exe, and set it on your local, for example, D:\NuGetLocalFolder.
Create a new project with project name "ConfigurationCore".
Open a cmd and switch to the path where nuget.exe was stored previously.
Use command line:
nuget spec "C:\Users\<Username>\Source\repos\ConfigurationCore\ConfigurationCore\ConfigurationCore.csproj"
You will find the .nuspec be genererated, Do not close this CMD window.
Edit the ConfigurationCore.csproj.nuspec file and modify it, below is my .nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>ConfigurationCore</id>
<version>1.2.0</version>
<title>Configuration Core</title>
<authors>MAKK</authors>
<owners>IT Department</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ConfigurationCore contains core funcationality of Software</description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2018</copyright>
<dependencies>
<dependency id="Newtonsoft.Json" version="10.0.3" />
</dependencies>
</metadata>
<files>
<file src="C:\Users\Admin\Source\repos\ConfigurationCore\ConfigurationCore\bin\x86\Test\ConfigurationCore.dll" target="lib\net461" />
</files>
</package>
Save ConfigurationCore.csproj.nuspec file, and back to your CMD window, using pack command to generate the nuget package:
The package ConfigurationCore.1.2.0.nupkg was created into the folder where nuget.exe exists, D:\NuGetLocalFolder.
This can happen because you are supplying a "nuget v3" url when only a "nuget v2" url is supported (in my case apt-get was giving me some ancient version of nuget). Typically a nuget source that supports v3 will also support v2, so if your url looks like
https://<something>/api/v3/index.json
try changing it to
https://<something>/api/v2
This is because you are referencing a non existing link: http://builtsrv1:8080/nuget/FindPackagesById()?id='ConfigurationCore'&semVerLevel=2.0.0'
You are using a method inside url, which is invalid and is the cause for the mistake:
//this is an error
../nuget/FindPackagesById()?
fix the url, test it and try again,

How can I restore NuGet packages from a custom package source when using LINQPAD's lprun.exe?

We use the lprun feature of LINQPAD to run our build scripts; However as we are in a corporate environment we block access to the NuGet.org package source:
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
And instead use a corporate proxy e.g. a custom package source:
<add key="MyProxy" value="https://proxy.server/custom-nuget-repo" />
When developing locally these sources are specified in:
C:\Users\Me\AppData\Roaming\Nuget.config
However LINQPAD is ignoring this file, how can I provide custom package sources when using the lprun to restore NuGet packages referenced?
From newer LinqPad versions this is built in to the LinqPad NuGet manager. Go to QueryProperties (F4) -> 'Add Nuget' -> 'Settings' and new package sources can be added just as easily as in VS.
Adding a new answer here since Google led me to this question first when trying to find the answer.
lprun and LINQPad both use the file %AppData%\LINQPad\NuGetSources.xml for NuGet Package sources, so this is the file you need to edit.
In case this file doesn't exist, here is an example:
<?xml version="1.0" encoding="utf-8"?>
<NuGetSources>
<Source Name="(default)" />
<Source Name="My Packages" URI="https://www.myget.org/F/your-username-here/" UserName="Example" Password="base64encodedstring" Enabled="false" />
</NuGetSources>

Categories