NuGet Pack -- Failed to retrieve information from remote source - nuget

I am trying to run:
nuget pack project.csproj
but because of the directory structure of the project:
A\B\C\Project
it keeps saying:
NuGet.Protocol.Core.Types.FatalProtocolException: Failed to retrieve information from remote source 'A\B\Packages', which it really should be 'A\Packages'. How do I change where NuGet looks for packages while establishing dependencies.
I have tried putting a NuGet.config in both the project directory as well as the Solution (in .nuget). I added this to the file:
<config>
<add key="repositoryPath" value="A\Packages" />
</config>
in both places and it made no difference (it always says A\B\Packages).

VisualStudio 2019: Tools > Nuget Package Manager > Package Sources:
Select nuget.org and specifically unselect the others options

Add NuGet.org reference in the package source
Go to tools -> NuGet package manager-> package manager settings
Select NuGet Package manager and then Package sources
Add the following source library.
Name: NuGet.org
Source: {"\Https://api.nuget.org/v3/index.json}

The error is a bit weird, but is already mentioned here.
It looks like NuGet by default expects a packages folder at the same location as the .csproj file.
I also had a custom project structure where the .sln was located in another folder.
At least I worked around this by creating a Symbolic link like this (open cmd with admin rights):
cd <your .csproj location>
mklink /d packages "C:\path\to\actual\packages"
This way NuGet thinks the packages folder exists and should be able to create your package.

For me it worked by adding NuGet.config in solution folder.

I was facing similar issue with core 3.1 and trying to upgrade package 'Swashbuckle.AspNetCore.SwaggerGe'.I found that i was doing typo in Package source url. I have corrected it [Tools => Nuget Package manager => Package manager setting => Package Source ] and issue got resolved.

If you use packages that have Semantic Versioning 2.0.0, please make sure that you are using the V3 feed, https://api.nuget.org/v3/index.json, in the NuGet configuration.

The issue may be caused by the way the nuget looks for the packages folder. It looks for a .sln file by traversing up the directory structure. If, in your case, directory A\B contains a .sln file then nuget will assume the packages folder would also be there.

On OSX you can add a symlink to trick nuget into building.
Run the following in the project folder to make nuget read from the parent (solution) directory that have a packages folder:
ln -s ../packages packages

In my case, I unchecked ALL the package sources except the one that I needed which was NuGet.org from NuGet Package Manager >> Package Sources. After this, the NU1301 error was gone.

In the case of Rider IDE another problem could cause this error:
if you configure your NuGet sources in the project let the Username and Password in the Rider Ui empty and instead add manually this section (packageSourceCredentials) to your NuGet.Config in the project folder:
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="YourNuget" value="<your_nuget_url>" />
</packageSources>
<packageSourceCredentials>
<YourNuget>
<add key="Username" value="<Username>" />
<add key="ClearTextPassword" value="<Password>" />
</YourNuget>
</packageSourceCredentials>
</configuration>

Related

Bug: Azure DevOps Artifact Feed set wrong Package Dependencies

We use our private Artifacts Feed on Azure DevOps Server 2020.1 (on-prem). I get a feed MyFeed and a feed MyFeedTest. I use the MyFeedTest for Staging our NuGet Packages. When they are stable, they get pushed to MyFeed. If a NuGet package in the feed has a dependency on another NuGet package in the feed, I use the following line:
<PackageReference Include="ext.lib.MyPackage" Version="*" />
The issue here is that the Azure DevOps Server determines the dependency by itself, and it takes the Versions from the staging package in MyFeedTest for the packages in MyFeed even when the package MyFeedTest get unlist, even when the whole feed MyFeedTest get deleted.
The Azure DevOps Artifact should not determine the dependencies to another package by itself, and it should not ignore the defined dependency setting inside the package project file (Version="*").
In the end, my collogues get the following error in Visual Studio:
The Dependencies of the Package ext.lib.MyPackage on Azure DevOps Server looks like:
But to remember, the package ext.lib.DevExpress in Version 13.1.5.3 do not exist after deleting the whole feed MyTestFeed.
So how can I solve that? Is it possible to configure the Azure DevOps Server to not behave like this? We can't use staging with that mechanism.
The issue here is that the Azure DevOps Server determines the
dependency by itself
This is not determined by Azure DevOps Server, but resolved by NuGet. Version="*" means the highest stable version. Here is the document about Floating version resolutions.
I used dotnet CLI to create NuGet package. Here is my sample:
1.Add package reference in the "*.csproj" file.
<ItemGroup>
<PackageReference Include="ext.lib.MyPackage" Version="*" />
</ItemGroup>
2.Use dotnet pack command to build a NuGet package. This will generate a "*.nupkg" file. Change the suffix of this file to zip and extract files.
3.We can find a "*.nuspec" file. Open this file with Notepad, we can find the following content:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>ext.lib.DevExpress</id>
<version>3.2.1</version>
<authors>ext.lib.DevExpress</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package Description</description>
<dependencies>
<group targetFramework="net5.0">
<dependency id="ext.lib.MyPackage" version="1.2.3" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
</package>
So we can find that before this package is pushed to Azure DevOps, the dependencies of the package have been resolved to explicit versions and this is the expected behavior.
If you don't need ext.lib.DevExpress as dependencies any more, you need to remove this package reference in your ext.lib.MyPackage and push your package again.

How to use Nuget in SharpDevelop?

I am newbie in SharpDevelop and want to download Nuget packages. But I couldn't find any information about this topic on google. How to get Nuget packages in SharpDevelop?
I have taken new nuget.exe from here, put it to c:\test, in cmd -> cd c:\test I then entered nuget to get all info, and tried then nuget install Newtonsoft.Json -version 13.0.1 - getting "nuget argument can not be null or empty" - advice helped - tried ONLY nuget install Newtonsoft.Json - result "nuget unable to find package" - advice helped - I created nuget.config file with such content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
and put it near my new nuget.exe previously loaded...
PROFIT: nuget install Newtonsoft.Json - RETURNED needed nuget package's dlls of Newtonsoft (JSON.NET)...
and through (left-mouse-button in your SharpDevelop project) Referencies - AddReference -> .NET Assembly Browser -> Browse -- you can choose necessary c:\test folder (in my case) and dll version in it and add it to your project...
the oldest version (4.0) is better choice for best compatibility with both OS with NET.Framework 4.0 and OS with NET.Framework later versions as well

nuget pack ignores package.config dependencies

I cannot get nuget pack X.csproj to recognize package dependencies in a project. Amazingly, when packaging, the diagnostic message “Found packages.config. Using packages listed as dependencies” is printed, but in the end the <dependencies/> tag in the .nuspec file inside the package is empty.
The packages.config for the project does indeed contain references:
<packages>
<package id="SmartAction.Logger" version="1.0.2.0" targetFramework="net40" />
<package id="SmartAction.Pervasive" version="1.0.1.0" targetFramework="net40" />
</packages>
To narrow the problem down, I removed my own parallel .nuspec file, and mostly all switches from the nuget pack command:
> nuget pack libToneDetection.csproj -prop Configuration=Release
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Attempting to build package from 'libToneDetection.csproj'.
Packing files from '[snip]\Core\ToneDetection\libToneDetection\bin\Release'.
Found packages.config. Using packages listed as dependencies
Successfully created package '[snip]\Core\ToneDetection\libToneDetection\SmartAction.Audio.ToneDetection.1.0.0.0.nupkg'.
NuGet Version: 3.3.0.212
The only difference I can spot with this project is that its name is different from package name (I am trying to maintain them in sync but this is older stuff I am repackaging).
I doubt I had ever seen this before. I am finding questions on SO from people trying to prevent references in packages.config from becoming dependencies of the package, but none from those trying, like me, to beat the reverse problem. Help!
Addendum. I copied the project out of the solution with other projects to a temporary directory and rebuilt the package from there. Now one of the two dependencies from packages.config was added to the package:
<dependencies>
<dependency id="SmartAction.Logger" version="1.0.2.0" />
</dependencies>
Thinking of the differences between the two, the SmartAction.Logger package depends on SmartAction.Pervasive. But the package I am compiling really uses both.
To me, either behavior looks incorrect. Am I hitting a nuget bug, or a cryptic complex feature?
Xref: Opened https://github.com/NuGet/Home/issues/1867

Deploying MVC4: System.IO.FileNotFoundException [duplicate]

I have a small web application. Which was working fine until I added two genericHandler in my application.
I have made the following changes for the http handler
<system.web>
<authentication mode="Forms" >
<forms protection="All" timeout="720" defaultUrl="Default.aspx" loginUrl="Login.aspx" >
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<!--Code Log Handler-->
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
<add verb="*" type="InfoDomeNewUI.Handler.SendOWA" path="SendOWA.ashx" />
<add verb="*" type="InfoDomeNewUI.Handler.SendSOS" path="SendSOS.ashx" />
</httpHandlers>
<customErrors mode="Off">
<error statusCode="404" redirect="Templates/PageNotFound.html" />
</customErrors>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<!--Code Log Handler-->
<add name="LogHandler1" path="SendOWA.ashx" verb="*" type="InfoDomeNewUI.Handler.SendOWA"/>
<!-- SMS SENDER-->
<add name="SendSOS" path="SendSOS.ashx" verb="*" type="InfoDomeNewUI.Handler.SendSOS"/>
</handlers>
</system.webServer>
Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I am using asp.net4.0 and C#. I am not using MVC
On local host it is working fine.
But when I am hosting the published code it is giving me the above error.
Stack Trace:-
[FileNotFoundException: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
System.Web.Http.WebHost.SuppressFormsAuthRedirectModule.Register() +0
[InvalidOperationException: The pre-application start initialization method Start on type System.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +11708830
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +465
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLeve
[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11697760
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4866485
It appears that Microsoft.Web.Infrastructure.dll is not being installed in the GAC, even if .net (4.0 or 4.5 or other) are installed successfully on Windows Server. On localhost (typically Windows client), it seems like it is being in the GAC when the tools/platform (Visual Studio etc.) are installed.
As one possible fix, please try the following:
Run the following command in the Package Manager Console. (If you are using Visual Studio, this can be reached via menu options "Tools --> Library Package Manager --> Package Manager Console:)
PM> Install-Package Microsoft.Web.Infrastructure
You will see the following messages if it is successfully installed.
Successfully installed 'Microsoft.Web.Infrastructure 1.0.0.0'.
Successfully added 'Microsoft.Web.Infrastructure 1.0.0.0' to Web.
You will notice that Microsoft.Web.Infrastructure.dll has now been added as a Reference (can be seen in the references folder of your project in in Solution Explorer)
If you look at the properties of this reference you will notice that "Copy Local" has been set to "True" by default.
Now when you "Publish " your project, Microsoft.Web.Infrastructure.dll will be deployed.
I installed MVC4 via WPI and it helped me.
I had the same problem. When I tried the accepted answer (rockyb), I got the message that the package was already installed and assigned to my project. When I checked the references list, it was NOT referenced, however.
The Microsoft.Web.Infrastructure was installed in my solution's packages folder. Instead of using NuGet to add the package, I just used the Add Reference option. On the left side of the pop-up window, I chose Browse, and then pressed the Browse button on the bottom of the window. I navigated to the packages folder under the folder that my solution was in, then drilled down to the ...\mysolution\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40 and clicked on the Microsoft.Web.Infrastructure.dll. After clicking OK, the package showed up in my References list. I used the Web Deploy Package option to deploy my website and everything worked.
Why not copy Microsoft.Web.Infrastructure.dll file manually to the server BIN folder. This works for. My project is VS2010 Website.
This file can be located:
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40
Just copy and paste it in the BIN folder.
You probably need to include this in the web.config if you don't have it already
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
Reference: http://thedeveloperblog.com/
I found the problem. Instead of adding a class (.cs) file by mistake I had added a Web API Controller class which added a configuration file in my solution. And that configuration file was looking for the mentioned DLL (Microsoft.Web.Infrastructure 1.0.0.0).
It worked when I removed that file, cleaned the application and then published.
After installing Microsoft.Web.Infrastructure through Nuget-Package Manager
PM> Install-Package Microsoft.Web.Infrastructure
Copy the Microsoft.Web.Infrastructure.dll manually from the Nuget-Package folder on your web application and then paste it in your bin folder of your web application deployed on the web server.
packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
It worked for me.
Update-Package -reinstall Microsoft.Web.Infrastructure didn't work for me, as I kept receiving errors that it was already installed.
I had to navigate to the Microsoft.Web.Infrastructure.1.0.0.0 folder in the packages folder and manually delete that folder.
After doing this, running Install-Package Microsoft.Web.Infrastructure installed it.
Note: CopyLocal was automatically set to true.
Sometimes needs to delete the package with force then reinstall it
its works for me.
try delete package
Uninstall-Package Microsoft.Web.Infrastructure -force
then install again
Install-Package Microsoft.Web.Infrastructure
I had the same problem and the "Microsoft.Web.Infrastructure.dll" appeared to be missing. I have tried few advises and installed MVC`s etc. and nothing helped. The solution was to install "Web Services Enhancements (WSE) 1.0 SP1 for Microsoft .NET" which includes Microsoft.Web.Infrastructure.dll.
Available at: http://www.microsoft.com/en-gb/download/details.aspx?id=4065
I had the same problem. I tried installing Visual Studio 2010 SP1 but it didn't worked.
Finally I get Microsoft.Web.Infrastructure.dll from the colleague. You can find the dll into your friends PC where the project is perfectly working. Try to search dll into Temp/Temporary ASP.NET Files. Go to Temp using %temp% into run window.
After getting dll into your pc, just add reference to your project and it will work.
Republishing the site fixed the issue for me.
Was facing the same issue and unfortunately nothing here was working. Finally, I came across this link: https://blogs.msdn.microsoft.com/jjameson/2009/11/18/the-copy-local-bug-in-visual-studio/
Turns out the solution is sort of dumb: set copy-local for the microsoft.web.infrastructure dll to False, then set it back to True.
By the way, I think what is happening is that there are two versions of the microsoft.web.infrastructure dll, one that is pre-installed in the GAC, and another one that is now a nuget package. I think one is masking the other, hence causing issues. In my particular case, on my build server, I need it to be copied over to a folder (this folder is then zipped and sent off to deployment). I guess the system had a copy locally and just thought "nah, it'll be fine"
I have a files only website. Added MVC 5 to webforms application (targeting net45). I had to modify the packages.config
package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45"
to
package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" developmentDependency="true"
in order for it to startup on local box in debug mode (previously had the top described error). Running VS 2017 on Windows 7...opened through File > Open > Web Site > File (chose root directory outside of IIS).
I had the same problem after upgrading a bunch of NuGet packages.
I have tried all kinds of deleting, cleaning, resintalling described here and beyong to no avail. The references did not have Microsoft.Web.Infrastructure despite the NuGet manager showed it was installed.
The problem was solved by replacing:
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
with
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
in packages.config. The culprit is apparently "net45".
Visual Studio 2022 .net.4.8
I just run this and is solved
you can install this dll using nuget package manager
PM> Install-Package Microsoft.Web.Infrastructure -Version 1.0.0

Packing NuGet projects compiled in release mode?

Is there some way to make a NuGet package using code compiled in release mode? Or is there some reason I should only publish (make available locally, in this case) packages compiled in debug mode?
Every time I call nuget pack from my project directory, where I have the nuspec file below, on code I have only compiled in release mode, it complains about not finding the DLL in the debug folder ("\bin\Debug\SomeProject.dll"). If I compile it in debug mode, those files are there and it packs them up as it should.
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<iconUrl>http://somewhere/project.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
</metadata>
</package>
You can solve it like this:
NuGet.exe pack Foo.csproj -Prop Configuration=Release
(reference)
If you are using a post-build event and you want to create a package whether using Debug or Release configuration you can setup the post-build event commandline like so:
"<path to nuget tools>\NuGet.exe" pack "$(ProjectPath)" -Prop Configuration=$(ConfigurationName)
To have NuGet automatically use Release mode when you run nuget pack, do the following:
Open your .csproj file in a text editor.
Find the following line:
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
In this line, replace Debug with Release.
Save changes.
The answers here are good, but I was having a lot of problems with this for a .NET Standard project. I had a project that was only going to publish Release binaries, but it wasn't respecting my default build output path.
I added this to my CSProj which then enabled me to use the accepted answer here.
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<OutputPath>$(SolutionDir)bin\$(PlatformTarget)\Release</OutputPath>
</PropertyGroup>
Chiming in here.
My build profile would build the DLLs to bin\<arch>\Debug|Release.
I was able to point to my folders by running the nuget command as follows:
Notice how I used the -p option.
PS > nuget pack -p Configuration="x64\Release"
Attempting to build package from ...
...
Found packages.config. Using packages listed as dependencies
...
- Add a dependency group for .NETFramework4.7.2 to the nuspec
Successfully created package...