Nuget Packages Installation - c#

I have a solution which has a two projects. In the both the projects I have packages.config file which has the list of packages that the project uses. Whenever I build the solution I'm getting the below error
The command "*\Tools\nuget install \packages.config -o \Packages" exited with code 3.**
(replaced folder path with **)
I have installed all the packages manually using package manager console. The installation is successful. When I build the solution now i'm getting the below error
The command "*\Tools\nuget install \packages.config -o \Packages" exited with code 1.**
I have cleared the cache of packages. Still I get this error. Not sure why the solution build is trying to install the packages.

You can try adding -verbosity detailed to your command *\Tools\nuget install \packages.config -o \Packages to get detailed error message to help you investigate the cause.

This was happening in a new CI build I set up yesterday. The problem was that NuGet.exe wasn't at the specified path.
"exited with code 3." wasn't an error from NuGet.exe but from MSBuild.

If you were using TFS, be sure to include the location of the Nuget package in the Source Settings of build definition. This error can indicate it cannot access the files.

Related

Problem after transferring files to another system (error NETSDK1)

After I import the files from another system to my system, I get the following error
Severity Code Description Project File Line Suppression State
Error NETSDK1005 Assets file 'C:\Users\user\Desktop\project1\project1\project1\obj\project.assets.json' doesn't have a target for 'net5.0'. Ensure that restore has run and that you have included 'net5.0' in the TargetFrameworks for your project. project1 C:\Program Files\dotnet\sdk\6.0.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 267
Update to Nuget 5.8 Clear the local cache
error NETSDK1005: Assets file 'project.assets.json' ....
Try updating NuGet.exe to the 5.8.0 version or above:
nuget update -self
if you prefer to update the nuget version in Visual Studio, just follow this steps. Then, clear NuGet cache:
dotnet nuget locals all --clear
reference

Nuget error when trying to publish in .Net5

When I publish in .Net5 I get the following Errors
Severity Code Description Project File Line Suppression State
Error Assets file 'C:\Users\cornelis.dejager\source\repos\Marel.MSAWebServiceAPI\Marel.MSAWebServiceAPI\obj\publish\win-x86\project.assets.json' not found. Run a NuGet package restore to generate this file. Marel.MSAWebServiceAPI 0
and
Severity Code Description Project File Line Suppression State
Error Failed to retrieve information about 'Microsoft.WindowsDesktop.App.Runtime.win-x86' from remote source 'https://api.nuget.org/v3-flatcontainer/microsoft.windowsdesktop.app.runtime.win-x86/index.json'.
An error occurred while sending the request.
The request was aborted: Could not create SSL/TLS secure channel. Marel.MSAWebServiceAPI 0
What caused it:
Not sure to be honest. After I changed code it stopped working. The project has been fine for weeks now and suddenly it changed.
I have tried
Cleaned solution
Build/Re-Build Solution
Restore The Nuget Packages
Update Visual Studio
Rebuild All projects
Delete Bin & Object folders
Update all packages
Restarting Visual Studio + Computer
Created new publishing profile
install dotnet-WindowsDesktop
Reinstall .Net5 Runtimes
Run the command:
Additional Info
It builds and run fine. Only when I publish it seems to give me an error.
I really do not why publishing isn't working. I've looked at several places but have not found a solution to it yet.
It may happen from the wrong package source,
In Visual Studio go to
Options=> Nuget Package Manager=> Package Sources
if you are using a custom source make sure you have entered the address correctly.
NuGet default source address is https://api.nuget.org/v3/index.json

C# Package not found on build even after installing

I installed the Newtonsoft.Json package through terminal on VS Code. On running the command "dotnet run" I get the error message:
"The type or namespace name 'Newtonsoft' could not be found"
together with other associated error messages.
How would I address this issue? Thanks
Try run dotnet build first then dotnet run.
The command depends on the dotnet build command to build the code.
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-run?tabs=netcore30
Based on John's questions above, I found that my installation may have been faulty, so I used "dotnet add package Newtonsoft.Json" to install Newsoft.
Upon restarting VS Code, I found that the errors had disappeared. My sincerest thanks to everyone here in helping me solve this issue.

Ignore inaccessible sources w/ dotnet add package

When I try to add a NuGet package via the dotnet cli I get an error that it can't access one of my custom NuGet sources. Is there a way to say "I don't care, restore from where you can"?
McMaster.Extensions.CommandLineUtils clearly it exists in NuGet.org and it finds it but then stops b/c it can't access a custom source 🤷‍♂️.
PS c:\Temp\blah-project> dotnet add package McMaster.Extensions.CommandLineUtils
info : Adding PackageReference for package 'McMaster.Extensions.CommandLineUtils' into project 'c:\Temp\blah-project\blah-project.csproj'.
info : Restoring packages for c:\Temp\blah-project\blah-project.csproj
info : GET https://api.nuget.org/v3-flatcontainer/mcmaster.extensions.commandlineutils/index.json
info : OK https://api.nuget.org/v3-flatcontainer/mcmaster.extensions.commandlineutils/index.json 147ms
error: Unable to load the service index for source https://myinstace.pkgs.visualstudio.com/_packaging/Blah/nuget/v3/index.json.
error: Response status code does not indicate success: 401 (Unauthorized).
The dotnet command has the option to specify --source. This allows you to only restore packages from a specific location, in this case you'd want to use
dotnet restore --source https://api.nuget.org/v3/index.json`
This should pull the packages down to your local NuGet store and solve the problem on your machine.
In order to add the package to your project you may need to manually add a <PackageReference> to your project like
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.6.0" />
Then running the restore command above will get the package for you.
As a more-permanent fix, you should put a nuget.config file in the root of the project/repository where you specify the package sources for that specific project. There are settings that you can set to override your system's global nuget configuration/sources. See more information on nuget.config. You can create a starting nuget.config in your repo with dotnet new nugetconfig
while restoring packages, dotnet make a call to all the package sources to get the package and uses the one that responds first.
In your case, because of some authentication issue it is not able to access that source. That source can be disabled using the below command and then try to pull the package.
dotnet nuget disable source <NAME> [--configfile <FILE>]
You might be able use the --ignore-failed-sources option.
I'd recently encountered similar issues when having authentication problems on a private feed, this allowed me to install the packages (was actually a tool using dotnet tool install) and address my auth issue at a later date.
See https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore for more info and options.

Assembly dependency already defined error

I'm having an issue when I try to build my project, I get this error:
'Newtonsoft.Json' already has a dependency defined for 'Microsoft.CSharp'
Everything I see about this says to update your nuget package manager, so I updated from VS 2015, to 2017 and that didn't work. I update VS2017 to the latest version, still getting that error when I try to build. I tried setting the build dialog verboisty to Diagnostic, but it did not change the text at all. What else can be causing this, because I'm stumped.
The error is accompanied by this error:
The command ""C:\Users\...\NuGet.exe" pack
"C:\Users\...\Project.csproj"
-Properties "Configuration=Debug;Platform=AnyCPU" -NonInteractive -OutputDirectory "C:\Users\...Debug" -symbols"
exited with code 1.
When I run the command manually in the command prompt, it just gives me the dependency already defined error.
EDIT
This was marked as a possible duplicate. It's not, the 3rd paragraph explains why.
Assembly dependency already defined error
You should update the nuget.exe version to 2.12 and above in the path "C:\Users\...\NuGet.exe".
According to the error message, that should be use old nuget.exe to pack the project with dependency netstandard.
As test, I used the old nuget.exe (2.8.6) to pack project with dependency Newtonsoft.Json 11.0.2 like your command line, I got the same error. To resolve this issue, you need to update the nuget.exe in the folder "C:\Users\...\NuGet.exe".
That is the reason why you already update the Visual Studio 2015 to 2017 and still have this issue, because you still use the old nuget.exe in the command line.
Hope this helps.

Categories