在 ASP.NET“网站”中使用 NuGet 和 *.dll.refresh 文件具有 Web 部署项目的项目
如果您有 ASP.NET 网站项目类型(没有正确的 .csproj 或 .vpproj 项目文件,只是一个松散文件的文件夹),那么当您使用 NuGet 添加包时,它会生成一个 *.dll Bin 目录中的 .refresh 文件以引用父包文件夹中的包的 dll。
例如,如果从程序包管理器控制台执行“install-package elmah”,则 Elmah 将放置在项目解决方案目录的 packages 文件夹中,文件 Elmah.dll.refresh 将放置在项目的 Bin 文件夹中。
当我在本地构建项目时,Visual Studio 会自动提取刷新文件引用的 DLL。该网站和 Elmah 运行正常。我没有将项目 Bin 目录中的 Elmah.dll 文件签入源代码管理(仅签入刷新文件和包文件夹)。
但是,我正在使用 Web 部署项目来预编译站点并为部署执行 web.config 替换。当以这种方式构建解决方案时,Elmah.dll 不会自动拉入网站项目 Bin 目录,并且由于缺少 DLL,该网站无法正常运行。
NuGet 打算如何用于这种场景?我应该检查 Bin 目录中的 Elmah.dll 吗?
If you have an ASP.NET Web Site project type (the one without a proper .csproj or .vpproj project file and that is just a folder of loose files), then when you add a package with NuGet, it makes a *.dll.refresh file in the Bin directory to reference the package's dll in the parent packages folder.
For example, if you execute "install-package elmah" from the Package Manager Console, then Elmah is placed in the packages folder in the project's solution directory, and the file Elmah.dll.refresh is placed in the project's Bin folder.
When I build the project locally, Visual Studio automatically pulls in the DLL referenced by the refresh file. The site and Elmah run correctly. I don't have the Elmah.dll file that sits in the project's Bin directory checked in to source control (only the refresh file and the packages folder are checked in).
However, I'm using Web Deployment Projects to pre-compile the site and do web.config substitutions for deployments. When the solution is built this way, Elmah.dll is not automatically pulled in to the web site project Bin directory and the site doesn't run correctly because of the missing DLL.
How is NuGet intended to be used in this kind of scenario? Am I suppose to check in Elmah.dll in the Bin directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是基于上面GC的解决方案。
添加类库 (csproj) 并在网站项目中引用该类库。
将 nuget 包添加到类库中。
在类库中,实际上引用了某个类文件中的nuget包。也许创建一个一次性实例或其他东西。您可以使用包中包含的任何类。这会强制将 .dll 复制到网站项目中的 Bin 目录。
This is based on GC.'s solution above.
Add a class library (csproj) and reference that class library in the website project.
Add the nuget packages to the class library.
In the class library, actually reference the nuget packages in some class file. Maybe create a throwaway instance or something. You can use any class that's contained in the package. This forces the .dll to be copied to the Bin directory in the web site project.
-- 编辑 -- 请参阅上面此解决方案的更新版本。
只需将类库项目添加到解决方案,并将对该类库项目的引用添加到您的网站即可。
然后,将nuget添加到类库中,而不是网站项目中。
当您的网站构建时,它会依次引入所有类库的依赖项。
-- EDIT -- See updated version of this solution above.
Just add a class library project to the solution, and add a reference to the class library project to your website.
Then, add the nuget in the class library, not the website project.
When your website builds, it pulls in all the class libraries' dependencies in turn.
我猜测预编译不会使用 .refresh 文件更新 DLL - 也许这是由 Visual Studio 完成的。
如果找不到方法,您可以创建一个构建步骤,手动将 DLL 复制到 bin 文件夹中,或者如果您试图避免 DLL 的两个副本,也许您可以签入 bin 文件夹而不是包裹之一。您可以使用 NuGet.exe 重新获取包,填充包文件夹(请参阅 此处 和 此处)
I'm guessing the pre-compilation doesn't update the DLLs using the .refresh file - maybe that's done by Visual Studio.
If you can't find a way to do it, you could create a build step that copies the DLLs into the bin folder manually, or if you're trying to avoid two copies of the DLLs, maybe you could check in the bin folder and not the packages one. You can use NuGet.exe to re-fetch the packages, populating the packages folder (see here and here)
我在 Visual Studio 2019 上运行 ASP.NET Web 表单时遇到了同样的问题。
我的解决方案是从本地 NuGet 目录刷新包
在记事本中创建一个新文件
本地包目录的相对路径
文件名: MyLibrary.dll.refresh
将刷新文件添加到 Visual Studio 中项目的 bin 目录中,如果您使用刷新文件,则将其包含在源代码管理中。
编译项目以确认文件已正确刷新。
I had this same problem with ASP.NET Web Forms running on Visual Studio 2019.
My solution was to refresh the package from the local NuGet directory
Create a new file in notepad
Relative path to local package directory
File name: MyLibrary.dll.refresh
Add the refresh file to the bin directory of the project in Visual Studio and include in source control if you use one.
Compile the project to confirm the file is correctly refreshed.