2

I've tried with Nuget Update, Nuget restore, but they are actually not the same and here's why:

I've created a Nuget pkg only to distribute an executable file. When I install the Nuget the executable is added to my project so I can reference it and run it within my application.

Now, I don't want that every developer has to install the Nuget to have the executable in their project, but I just want the .exe to be added when the project is built. And of course, the reference to the package in the config file is present.

If I run Update-Package -Id -reinstall(using the Package Manager of VS) a folder with the .exe is added to the project root, but if I do nuget update or nuget restore (using the nuget CLI) it only re-add the .exe into the packages folder.

The reason why I need to run the nuget CLI is because I'm using TeamCity and I want to add the .exe when the automatic build runs.

I hope it makes sense.

Sergio
  • 241
  • 3
  • 15
  • Check this: https://stackoverflow.com/q/17733307/7225096 This is old question but imho nothing changed since nuget 2.8. – Peska Jul 19 '18 at 07:17

1 Answers1

3

How reproduce VS2017 Package Manager command “Update-Package -reinstall” with Nuget CLI

I am afraid you can NOT do such things with NuGet CLI. That because NuGet CLI does not modify a project file or packages.config. When we modify the project file, we need to do it by NuGet API in Visual Studio, but only package manager console can provide access to visual studio objects:

https://github.com/NuGet/Home/issues/1512

That is the reason why I said the easiest way is using the command line Update-Package -Id -reinstall in your previous thread. Then I also gave you another way to resolve this issue from the root cause, using .targets file to copy the executable file to the the project root, please check my update answer.

Of course, there is another simple idea to resolve this issue, just add a pre-build event in your project to copy the executable file to the the project root:

xcopy  /Y "$(SolutionDir)packages\MyToolPackage.1.0.0\Tools\wkhtmltopdf.exe" "$(ProjectDir)"

Hope this helps.

Leo Liu-MSFT
  • 52,692
  • 7
  • 69
  • 81