Is there an equivalent to Update-package -reinstall when using nuget.exe? - nuget

I don't know why. But whenever I pull code from a repo that someone else has worked on their .csproj comes with changes that don't work on my machine. In this case, I have found that:
Sometimes running Update-Package -reinstall fixed reference problems
Sometimes opening the .csproj file and then manually removing errors works
I suspect this is something to do with the reference paths defined in the .csproj file, and that the Update-package -reinstall command fixes those references relative to the local machine that the project is being built.
is there a way to replicate the Update-package -reinstall command using nuget.exe?

you need to run nuget.exe restore packages.config -PackagesDirectory <packages_directory> where packages_directory is the directory where you want your packages to be downloaded.
You can read more about the restore operation here.
I would recommend that you standardize the build steps in a shared script in your repository. For instance -
wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile nuget.exe
& nuget.exe restore packages.config -PackagesDirectory packages_directory
& msbuild /t:build project.csproj

Related

I have many solution files in one repository, i want all solution files to restore using nuget ina single command

I have many solution files in one repository, i want all solution files to restore using nuget using a single command.
Or is there any other way instead of giving all solution file names one by one
eg:
Nuget restore solution1.sln
Nuget restore solution2.sln
Nuget restore solution3.sln
i tried below command but no luck
nuget restore **'\'*.sln

nuget.exe doesn't restore all packages

When I run:
nuget.exe restore c:\path\to\my.sln
It creates directory c:\path\to\packages, but it only restores one of 4 nuget packages used by the solution. It only restores EntityFramework.6.2.0.
When I open the same solution in Visual Studio and rebuild, then my c:\path\to\packages\ directory also contains:
EPPlus.4.5.3.1\
NPOI.2.4.1\
SharpZipLib.1.0.0\
The solution only contains a single project.
Why does nuget.exe restore not restore all packages, instead of just restoring one of them?
Is there some command line argument to retrieve non-Microsoft packages? I didn't see one in the Nuget docs.
I updated nuget,
nuget.exe restore c:\path\to\my.sln
...and that seems to have solved the issue. I was previously using version 2.X.

How to update / reinstall executable stored in NuGet

I would like to use NuGet to avoid adding a 3rd party executable to git repository.
I have a NuGet package with executable published to our NuGet source. Package contents:
content\SetupFiles\bigexecutable.exe
I've added the NuGet reference to the project in which I want to use the executable. It properly adds the
SetupFiles\bigexecutable.exe
to the project directory during the NuGet package installation. But if I delete the file from the project directory it is not replaced during the build.
Is it possible that NuGet would verify if the package contents are present before the build and reinstalled the package if something is missing?
Your .exe is being added to the project since you are including it in the Content directory. NuGet will not restore items into the project. It will only restore items into the packages directory.
An alternative would be to create a tools NuGet package where the .exe is not added to the project but is available in a tools directory relative to the solution's directory.
The NUnit.ConsoleRunner is one example of such a NuGet package where it has all its .exe files in the tools directory. Using the tools directory does not cause NuGet to add any files to your project.

Updating NuGet package causes Source Control error because content files are not overwritten

Quite often when installing some of the js* library packages nuget copies js files to Scripts directory of the web project and puts these files under source control.
Yet while updating the package instead of just rewriting the files nuget first removes them and then copies new versions. Because of that TFS shows the error about conflicting state: Files are scheduled for removal but present locally.
Can we somehow change this behavior or is it completely defined by the author of the package?
No, this behavior is not defined by the package author.
And since NuGet 2.5, it is allowed to overwrite content files that already exist. Check: https://docs.nuget.org/release-notes/nuget-2.5
You need to use the Update-Package command to update NuGet packages.

Nuget restore command from different directory

I try to run the following nuget command ,
in the "D:\work\Development\" directory there is solution file
nuget.exe restore D:\work\Development\
I received an error
Could not find a part of the path C:\work\Development
When I copy the nuget.exe file to the directory D:\work\Development and run resotre like so
nuget.exe restore
from there it works
How can I make restore work from another directory than the one my solution is in?
What I ended up doing is using restore from with a relative path like so :
nuget.exe restore ..\
You should pass in the path to the .sln file, such as D:\work\Development\mysolution.sln or path to the packages.config file.
Please refer to this doc for how to use the nuget.exe restore command.
http://docs.nuget.org/docs/reference/command-line-reference#Restore_command
I had a similar issue getting a relative path to work, but in my case I was accessing the nuget.exe in a subfolder as well as trying to restore packages in another folder.
I realised that the restore command path is based on the directory you are running the command from, not the directory the nuget.exe file is in.
eg. If your nuget.exe file is in a Projects\.nuget subfolder, and you are in the root directory (one up from Projects), running this will restore any packages for a solution that is in the Projects subfolder.
Projects\.nuget\nuget.exe restore Projects