Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Visual Studio is referring the actual NuGet referenced DLL?

I've added Autofac library using NuGet and I see it in my references as shown below.

enter image description here

But when I check the properties [F4] of Autofac by clicking on it, it shows empty property box in Visual Studio.

enter image description here

Also, I don't see Autofac folder under packages folder.

enter image description here

I see only Package reference in .csproj file. Then how does it locates the DLL? Where is the actual DLL? I see it's automatically coming inside BIN. How does it come?

enter image description here

Main Issue: Locally I'm able to build the solution but same solution fails on TFS build agents. It's unable to find the NuGet reference. So where can I find DLL references? or how to push it to TFS?

like image 444
kudlatiger Avatar asked Jun 12 '18 10:06

kudlatiger


People also ask

Where are NuGet references stored?

NuGet keeps a configuration file that defines some basic options about how and from where to retrieve these packages: On Windows, the NuGet. config file is kept in %AppData%\NuGet.

How can I see where a DLL is referenced?

Select View in Object Browser. Expand the object that corresponds to your dll. Expand the namespace. Right click the class and select Find All References.

Where does Visual Studio look for NuGet packages?

The global-packages folder is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder.


2 Answers

As @magicandre1981 already explained, with PackageReference style package referencing (as apposed to package.config-style, also see this for more background on the differences, in case you didn't know), the packages are not located in a per-solution packages-folder, but in a central one (by default %USERPROFILE%\.nuget\packages). Albeit you can easily change the location using the NUGET_PACKAGES environment variable (which also works as a TFS Build variable, because they are provided as environment variables to build steps).

Furthermore, inside Visual Studio you see no path, because the actual path to the DLL is determined at build time. You can see part of that path in your <project-dir>\obj\project.assets.json file (which is generated during the restore target/operation), but the full path you will only see in the MSBuild logs (for example when actually calling the csc.exe executable/C# compiler or during ResolveAssembyReferences-task).

Note that for .NET Core, i.e. "SDK style" projects, the path is actually shown in properties (as are the actual DLLs in a node underneath the "package" node.

PackageReference in SDK-style projects

One can only assume that the integration of PackageReference in "old" projects is not fully done yet (if ever).

For comparison a PackageReference in an "old" / non-SDK-style project:

PackageReference in non-SDK-style/old project

like image 142
Christian.K Avatar answered Oct 05 '22 23:10

Christian.K


You use the new Package Reference where the NuGet files get get stored into a cache:

Solution-local packages folders are no longer used – Packages are now resolved against the user’s cache at %userdata%\.nuget, rather than a solution specific packages folder. This makes PackageReference perform faster and consume less disk space by using a shared folder of packages on your workstation.

like image 31
magicandre1981 Avatar answered Oct 06 '22 00:10

magicandre1981