Azure Devops build not restoring automapper nuget - c#

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.

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.

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>

Change current web.config with custom Nuget package

I am new at creating custom nuget package. I used NuGet Package Explorer and added new Class Library dll to my local nuget repository. Now I can install it to my new projects.
But Sometimes I need install my custom package and change current project web.config file. Add new key or section. Is this possible?
You can modify the web.config through a web.config.transform file or by using an XML document transform (XDT).
For a .transform you create a web.config.transform file and put in the Content directory of your NuGet package. The web.config.transform file contains the same as a web.config file and it will be applied to the web.config file when you install the NuGet package.
XDTs are more powerful and can do more complicated modifications to the web.config file, such as inserting or removing existing elements. You create a web.config.install.xdt and optionally a web.config.uninstall.xdt file in the Content directory of the NuGet package. These transforms are then run when the NuGet package is installed or uninstalled. An example, taken from the NuGet documentation, is shown below.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<modules>
<add name="MyNuModule" type="Sample.MyNuModule" xdt:Transform="Insert" />
</modules>
</system.webServer>
</configuration>
The full XDT syntax is documented on the MDSN website

Azure CI using alternative nuget feed

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>

Categories