NuGet CLI not restore the package for the packagereference - nuget

I have created a new .net core project with Visual Studio 2017, then add a nuget package Newtonsoft.Json to the project. After that I know the package will cached at the folder C:\Users\<UserName>\.nuget\packages.
For some reason, I have to delete it, then I want to restore it, but I could not restore it with nuget.exe. nuget.exe restore, command can be executed successfully, but the package is not downloaded to that folder.
I also have tried the command MSBuild /t:restore, but it still does not work, package not download.
Any suggestion?

Related

Accessing Nuget Package Manager console in github actions

I have a fairly messy website project in C#
It has the layout of
Foo-EUR
Foo-EUR-Web
Where Foo-EUR has a csproj file and Foo-EUR-Web does not. It's just a website.
To get this to build locally I need to go to the Package Manager console for nuget and enter:
Update-Package -reinstall -project Foo-EUR-Web
This then copies all the dlls to the folder Foo-EUR-Web\Bin
If I don't do this, I get the error:
error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.
My problem is I'm trying to build this on github actions. I don't have Update-Package available.
I've tried
nuget restore src/Foo-EUR.sln
nuget restore src/Foo-EUR/packages.config
nuget restore src/Foo-EUR-Web/packages.config -PackagesDirectory packages
Nothing is working.
I think the issue is because there is no csproj, but adding one would be problematic.
Is their a way to install the Nuget Package manager into powershell as a github action to allow me to run Update-Package to get this to build ?
Or is there something else I'm missing here with nuget?
The framework version is 4.6.1

Nuget config and dnu restore on fresh windows install

After getting a new server up and running, I tried to get a dnx project working. I ran dnu restore on a project, and get this error.
Errors in C:\apps\ElasticIndexer\app\project.json
Unable to locate Dependency TestApplication >= 1.0.1
Feeds used:
https://api.nuget.org/v3-flatcontainer/
My issue is that I am unable to change the nuget feed used, as we host our nuget packages on a different server. I searched in %appdata% and there was no folder for nuget. I then decided I would do a search for nuget.config on the whole server and there was no nuget.config file.
I don't want to install Visual Studio on this server, but is there a reason why I don't have a nuget folder in my %appdata% folder? How does dnu know to search api.nuget.org by default? When installing latest dnvm is it supposed to create the nuget location as well, or do I need to manually create the folder and config file?
If there isn't a nuget.config file on your server you could try running nuget install. If that doesn't work try updating the sources via the command line:
NuGet.exe Sources Add -Name <feedName> -Source <pathToPackageSource>

Why windows C# projects contain nuget executable in .nuget folder?

I don't understood the overall scheme on how NuGet is used on windows platform (because I never saw this, I work with Linux and monodevelop).
In many windows projects, there is a .nuget folder in repository, like
https://github.com/YAFNET/YAFNET/tree/master/yafsrc/.nuget
In this folder there is a nuget.exe executable.
Why it is necessary to add executables to source code control(SCC)?
How NuGet build tool differs from all other binary tools like compilers, which are not included into SCC?
Why other package managers like paludis are not added to SCC, but nuget does?
What are exactly the reasons to put NuGet to SCC?
It is not necessary to add NuGet.exe to source control.
The reason some projects have .nuget/NuGet.exe, with a set of other MSBuild files, is to use the MSBuild based package restore. The MSBuild based package restore will run NuGet.exe at build time to download any missing packages.
The MSBuild based package restore has been deprecated by the NuGet team.
Visual Studio with recent versions of the NuGet Package Manager will automatically restore NuGet packages before building the project. If you need to restore NuGet packages on a build server you can use NuGet.exe to restore the NuGet packages by running a command line similar to:
NuGet.exe restore YourSolution.sln

Restoring NuGet packages

I have a C# solution containing several projects. Some of projects has referenced nuget packages. Whole solution (but no downloaded dlls) is tracked by git repository.
After cloning it to other place and trying to build nuget asks if it should download missing packages. After downloading there are still several referenced library missing.
I can fix it one by one doing following steps:
Remove reference
Remove package in packages.config file
Install this package again by nuget
Is there any better way to do this? I tried reinstalling all nuget packages, but my Visual Studion crashes. After restarting and retrying it left me with more missing packages.
Another way to do this is running:
PM> Uninstall-Package {Name}
PM> Install-Package {Name}
for each missing package. By missing package I mean all packages with yellow mark. I can't install it without uninstall command, becasue nuget says it is already referenced.
If you try running the following from the command line does it restore all the packages?
nuget.exe restore YourSolution.sln
If not then it sounds like there's some packages that are missing from your project's packages.config file.
You could try the updating the packages with the reinstall parameter from the PowerShell console.
Update-Package –reinstall <packageName>
You can also restrict this to one project if you want to by using the -ProjectName parameter.
This is probably because of the incorrect path of the .dll in your .csproj. The package restore downloads the packages to the local directory.
It doesn't change the reference path of the assembly in the .csproj, meaning that the project will still try to locate dlls on the local directory. The yellow mark means the project is unable to locate the assembly.
Unload the project, right click on project and select "Edit .csproj", and verify the path of missing dlls.
For example - If you have NUnit,
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
verify if the dll is present inside "\packages\NUnit.3.6.1\lib\net45" directory.

OctoPack failing in TFS Build

I'm using Visual Studio Online with Visual Studio 2013. The build fails with
You are trying to build with OctoPack, but the NuGet targets file that OctoPack depends on is not available on this computer. This is probably because the OctoPack package has not been committed to source control, or NuGet Package Restore is not enabled
According to this link https://octopusdeploy.com/blog/octopack-3.0 I need to make some changes to get package restore working properly, but another link within the previous one says that no configuration is required if using VS2013 and Visual Studio Online Nuget.org
When I build in VS all of the packages get restored first and then the project builds. Also if I build the project and invoke Octopack via command line everything works fine. Thoughts?
If you do run NuGet Package Restore before building, this should work. However, make sure the path in your project file referring to OctoPack.targets is correct - you might have moved your packages folder or the project file and the relative paths no longer match. Easiest way to fix it would be to run Update-Package -Reinstall Octopack.
NuGet Package Restore was recently changed so you wouldn't need to include NuGet in the solution to do a package restore. However, OctoPack still needs NuGet on the path so it can find it. You can try explicitly specifying the path to NuGet by adding this parameter when calling OctoPack.
/p:OctoPackNuGetExePath=<path>\nuget.exe
You just need to check in the Octopack targets file.
\packages\OctoPack.2.0.26\targets\OctoPack.targets