5

I am wondering if anyone is aware of how to properly include an Nuget package in my application. Installing it - adds the references automatically in Solution Explorer. In addition it create/display a file called package.config - and it looks like it wants to be added in my project. It is shown in Solution Explorer but appears in my root folder with a little + sign next to it - and allows me to Check In Pending Changes / add it. Am I supposed to add it to my project?

enter image description here

I basically don't want to screw up anything.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
BobSki
  • 1,531
  • 2
  • 25
  • 61

2 Answers2

5

Yes the packages.config file is required. This file holds the packages you reference and the versions youre using. NuGet uses this file to restore your packages in a TFS build of on the machine of another developer.

Here is some more information on NuGet dependency resolution

Note that you should not checkin the packages folder in your solution folder. NuGet will restore packages to this folder using the packages.config file

UPDATE: the <PackageReference> format was introduced a while back. It can be used with both the old and new .csproj formats. One of the benifits is that the paths to the packages are no longer in your project file so you will get a lot less updates/merge conflicts when updating NuGet packages. See this page for more information: https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files

Sander Aernouts
  • 959
  • 4
  • 16
  • Okay that makes sense - however, when I try to deploy the .exe - it still gives me error that the .dll (for which I installed the Nugget file) is missing. It works perfectly fine out of TFS - says COULD NOT LOAD FILE OR ASSEMBLY – BobSki Mar 15 '17 at 17:50
  • 1
    How do you build your .exe? Using a TFS build? Is the DLL you referenced through NuGet missing in the output of the build? – Sander Aernouts Mar 15 '17 at 17:52
  • I do REBUILD APP, then COMPILE - then go to source folder - bin/debug - grab the .exe and deploy it. The references are in the packages folder, and are clearly visible in solution explorer. I've never added a 3rd party library to my project. And after 2 days it's driving me crazy. Everything works in Visual Studio - only when i deploy it does it not work – BobSki Mar 15 '17 at 17:54
  • 1
    Grabbing only the .exe isnt enough. You need to deploy the .exe including all assemblies it relies on that are not already available in the environment you deploy to. Try to deploy the entire debug folder to check if your exe runs on the environment – Sander Aernouts Mar 15 '17 at 17:56
  • No idea how to do that - are all my .dll from the nugget package supposed to be in the obj/debug folder? - I've only ever deployed from .exe and never had any issues – BobSki Mar 15 '17 at 18:07
  • 1
    Yes, grab the .exe and all .dll's that are in your bin/debug folder. – Sander Aernouts Mar 15 '17 at 18:11
  • and do what with them? I need an .exe only @sander – BobSki Mar 15 '17 at 19:53
  • 1
    The CLR must be able to find all assemblies you reference. Deploying the required DLL's in the same folder as your .exe means the CLR will find them. You can find more information here https://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.110).aspx. Why do you need to deploy only the .exe. it is quite usual to deploy the required DLL's allongside your .exe. – Sander Aernouts Mar 15 '17 at 20:00
  • I've been deploying the .exe without any issues - until now where I actually need to use a third party library. How do i combine the dll's and exe into a final.exe. That seems to be what I need to do! But I have no clue how.I'm hoping to do that directly from VS – BobSki Mar 15 '17 at 20:05
  • 1
    @BobSki don't understand what the issue is with deploying multiple files instead of a single .exe. But I would go with ILMerge to merge extra DLL's into the .exe. I found a question that shows how this should be possible: http://stackoverflow.com/questions/10137937/merge-dll-into-exe – Sander Aernouts Mar 16 '17 at 07:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/138259/discussion-between-sander-aernouts-and-bobski). – Sander Aernouts Mar 16 '17 at 18:05
  • Updated the answer with the PackageReference style of referencing NuGet packages – Sander Aernouts Dec 21 '18 at 07:57
2

Yes, it's usually checked in as part of your solution. Source control and all that.

Jim Roth
  • 399
  • 2
  • 9
  • Yes; Right now I have added to an old ASP.NET VS Solution, the AntiXSS package from NuGet, and Visual Studio automatically checked out that file; This is the added line: ... So now I already have the file packages.config in the 'Included Changes' section of Team Explorer, ready to be checked in. – Roger Oct 18 '22 at 14:54