Using NuGet with *.dll.refresh files in ASP.NET "Web Site" projects with Web Deployment Projects
Asked Answered
Z

4

12

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?

Zirkle answered 12/5, 2011 at 10:6 Comment(0)
R
12

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.

Raimundo answered 23/2, 2013 at 17:8 Comment(1)
This is tested and works both in Visual Studio and by running MSBuild directly in a build machine.Raimundo
M
6

-- 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.

Metage answered 11/5, 2012 at 11:35 Comment(0)
B
0

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

..\packages\MyLibrary.0.0.0.0\lib\net45\MyLibrary.dll

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.

Brumley answered 12/5, 2011 at 10:6 Comment(0)
K
0

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)

Kernel answered 12/5, 2011 at 16:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.