简体   繁体   English

Visual Studio 在哪里引用实际的 NuGet 引用的 DLL?

[英]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.我已经使用NuGet添加了Autofac库,并且在我的参考文献中看到了它,如下所示。

在此处输入图片说明

But when I check the properties [F4] of Autofac by clicking on it, it shows empty property box in Visual Studio.但是当我点击 Autofac 的属性 [F4] 时,它在 Visual Studio 中显示空属性框。

在此处输入图片说明

Also, I don't see Autofac folder under packages folder.另外,我在packages文件夹下没有看到Autofac文件夹。

在此处输入图片说明

I see only Package reference in .csproj file.我在.csproj文件中只看到包参考。 Then how does it locates the DLL?那么它是如何定位DLL的呢? Where is the actual DLL?实际的 DLL 在哪里? I see it's automatically coming inside BIN .我看到它自动进入BIN How does it come?它是怎么来的?

在此处输入图片说明

Main Issue : Locally I'm able to build the solution but same solution fails on TFS build agents.主要问题:我可以在本地构建解决方案,但相同的解决方案在 TFS 构建代理上失败。 It's unable to find the NuGet reference.无法找到 NuGet 参考。 So where can I find DLL references?那么在哪里可以找到 DLL 引用呢? or how to push it to TFS?或者如何将其推送到 TFS?

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 ).正如@magicandre1981 已经解释过的那样,使用PackageReference样式的包引用(与package.config -style 相关,如果您不知道,也可以参阅了解有关差异的更多背​​景信息),这些包不位于每个解决方案中包文件夹,但在一个中央文件夹中(默认情况下为%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).尽管您可以使用NUGET_PACKAGES环境变量轻松更改位置(它也可用作TFS 构建变量,因为它们是作为构建步骤的环境变量提供的)。

Furthermore, inside Visual Studio you see no path, because the actual path to the DLL is determined at build time.此外,在 Visual Studio 中您看不到任何路径,因为 DLL 的实际路径是在构建时确定的。 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).您可以在<project-dir>\\obj\\project.assets.json文件(在restore目标/操作期间生成)中看到该路径的一部分,但您只会在 MSBuild 日志中看到完整路径(例如当实际调用csc.exe可执行文件/C# 编译器或在ResolveAssembyReferences -task 期间)。

Note that for .NET Core, ie "SDK style" projects, the path is actually shown in properties (as are the actual DLLs in a node underneath the "package" node.请注意,对于 .NET Core,即“SDK 样式”项目,路径实际上显示在属性中(就像“包”节点下的节点中的实际 DLL 一样。

SDK 样式项目中的 PackageReference

One can only assume that the integration of PackageReference in "old" projects is not fully done yet (if ever).只能假设 PackageReference 在“旧”项目中的集成还没有完全完成(如果有的话)。

For comparison a PackageReference in an "old" / non-SDK-style project:为了比较“旧”/非 SDK 样式项目中的 PackageReference:

非 SDK 样式/旧项目中的 PackageReference

You use the new Package Reference where the NuGet files get get stored into a cache :您使用新的包参考,其中 NuGet 文件被存储到缓存中

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.不再使用解决方案本地包文件夹 – 现在根据%userdata%\\.nuget处的用户缓存解析包,而不是解决方案特定的包文件夹。 This makes PackageReference perform faster and consume less disk space by using a shared folder of packages on your workstation.通过在工作站上使用共享的包文件夹,这使得 PackageReference 执行速度更快并消耗更少的磁盘空间。

Assume you are using TFS 2015, the NuGet Restore task name should be NuGet Installer which under Package when you add tasks.假设您使用的是 TFS 2015,NuGet 还原任务名称应为NuGet Installer ,当您添加任务时,该名称位于Package下。

So, if you have installed Nuget in the build machine, then you can use the task directly.因此,如果您在构建机器中安装了 Nuget,那么您可以直接使用该任务。 You can also custom nuget.exe for TFS 2015 build -- Just specify the Path to NuGet.exe您还可nuget.exe TFS 2015 构建自定义nuget.exe -- 只需指定Path to NuGet.exePath to NuGet.exe

You can refer to Mummy's blog- Custom nuget.exe for TFS 2015 build for details.您可以参考Mummy 的博客 - 用于 TFS 2015 构建的自定义 nuget.exe 以了解详细信息。

在此处输入图片说明

NuGet Restore任务添加到您的构建中,以便还原包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM