66

We have several external DLL files being referenced in our Web Application Project. We have a deployment project for installing on the hosting servers. When we were using .NET 3.5 and Visual Studio 2008 the DLL files were being copied to the bin folder. Since we have upgraded to .NET 4 and Visual Studio 2010 this no longer happens, and we are getting server errors since the references cannot be found.

CopyLocal is set to true, and I cannot find anything inside the web.config which suggests this is being set elsewhere.

R.J. Dunnill
  • 2,049
  • 3
  • 10
  • 21
g.foley
  • 2,152
  • 3
  • 19
  • 27
  • Could be related to: [Msbuild doesn’t copy references (dlls) if using project dependencies in solution](http://stackoverflow.com/questions/1132243/msbuild-doesnt-copy-references-dlls-if-using-project-dependencies-in-solution) – Roman Jun 01 '10 at 02:48

15 Answers15

107

There is a bug in Visual Studio 2010, 2012, 2013, 2015, 2017, 2019, 2022. By default the XML in the solution file looks like this:

<Reference Include="DevExpress.SpellChecker.v11.1.Core,
           Version=11.1.5.0,
           Culture=neutral,
           PublicKeyToken=b88d1754d700e49a,
           processorArchitecture=MSIL">
<HintPath>..\References\DevExpress.SpellChecker.v11.1.Core.dll</HintPath>
</Reference>

Whereas MSBuild is expecting this below, so that the DLL file will be included in the deployment:

<Reference Include="DevExpress.SpellChecker.v11.1.Core,
           Version=11.1.5.0,
           Culture=neutral,
           PublicKeyToken=b88d1754d700e49a,
           processorArchitecture=MSIL">
<HintPath>..\References\DevExpress.SpellChecker.v11.1.Core.dll</HintPath>
<Private>True</Private>
</Reference>

The trick is to set Copy Local to False, save the project and then reset it to True - save again. This includes the Private node correctly, which MSBuild respects.

It appears that the default for no included private node (Copy Local) in Visual Studio 2010 is True, while MSBuild reads that missing node as False.

Rebecca
  • 13,914
  • 10
  • 95
  • 136
  • 24
    Bug is still there in VS2012. It really should be fixed, took me a while to find this solution. – snaits Feb 28 '13 at 07:17
  • 5
    Today I discovered that this CopyLocal trick does not affect the references above the current project. For example, I have a project Entities which references some.dll in GAC. If I force CopyLocal=true for some.dll as described above, everything seems fine - some.dll gets copied to the bin folder of Entities. But if I reference the Entities project in some project Services and expect to get some.dll copied to the Services\bin, it won't happen - Services project ignores CopyLocal=true of the Entities project and still grabs the some.dll from the GAC. Using VS2012. – JustAMartin Aug 27 '13 at 12:34
  • Although this fixes the project file, this setting is still not respected by MSBuild.exe from the command line so any sort of automated build scripts will not be building the code correctly (e.g. the referenced project reference dll will not be in the bin directory) – longda Feb 10 '14 at 20:08
  • @longda I am having the same problem. I have project references that should be copied over, but even with Copy Local to true and Private to true, msbuild in command line will not copy them over. – Didier A. Mar 18 '14 at 19:49
  • I also get this issue. Complete waste of time, Microsoft should fix this. – Matthew May 27 '14 at 15:41
  • 3
    I'm running into this is VS2013 when I configure nuGet to supply missing packages. The only way I've found to succesfully work around this is to add references to the missing assemblies to my starting project. Yecch. – empty Nov 25 '14 at 18:22
  • There are probably many Connect bugs on this type of issue - I added one as best I could explain! https://connect.microsoft.com/VisualStudio/feedback/details/1113297 Feel free to vote on it!! Post here if you find a better connect issue to use..... – Paul Kohler Feb 03 '15 at 06:01
  • 11
    I just had the same issue in VS2015. FYI, the XML references mentioned in this answer are stored in the project file, not the solution file. – philreed Aug 21 '15 at 08:58
  • 1
    Adding VS2017 to the list – FishySwede Dec 14 '17 at 12:40
  • 1
    VS2017 still has this bug :( – Yesh Jan 17 '19 at 21:07
  • 1
    VS2022 still has the bug. You need to do better Microsoft. – Dmitri Caragheaur Aug 26 '22 at 09:49
3

Something weird had happened to my deployment project. When I saw it had no detected dependencies, I removed the primary output and re-added it.

The dependencies are now showing up and being placed in the bin folder when installed.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
g.foley
  • 2,152
  • 3
  • 19
  • 27
  • Great. just one question: How did you find out that it had no detected dependencies? which option is this in? please elaborate. thanks – VoodooChild Jun 01 '10 at 04:52
  • In my deployment project there is a detected dependencies folder. The only thing it was detecting in there was the .net framework. You can right click on this folder and click "Refresh dependencies", but even this wasn't working for me. When i re-added the primary output the dependencies were detected. It was very odd, and was caused sometime during the conversion between vs2008 and vs2010. I'd say its a bug but for the fact that all my other deployment projects converted perfectly. At the end of the day i have no idea what has happened. – g.foley Jun 01 '10 at 23:52
  • I had the same problem with a newly created solution in vs.net 2010, so it is not an upgrade issue. As you said, removing the primary output and readding seems to fix the issue. – Paul Hiles Mar 15 '11 at 17:02
  • could someone please clarify what "remove the primary output" means? – Brian Chavez Mar 25 '12 at 14:27
  • he likely means this: http://image.prntscr.com/image/1769f5e6958c4f89a865ed35d5e92224.png – aeroson Mar 30 '17 at 13:30
3

I was getting the same problem and rather than add a "BeforeBuild" step I created a test that simply did this

    [TestMethod]
    public void ReferenceAssemblyThatDoesNotCopyToBuildFolder()
    {
        Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler referenceThisButDoNotUseIt = null;
    }

And that fixed the error The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler...' cannot be resolved

stevie_c
  • 990
  • 1
  • 8
  • 15
2

I just had the same issue and wanted to share what I found as it might help someone:

The reason in my case was that the assembly was installed in the GAC during an installation of some third-party application.

If the DLL file is in the GAC, the compiler won't bother to copy it to the destination folder, unless you specifically mark it for "copy local" using the "Private" node in the project file as mentioned by Junto.

The thing is that if you don't add that node, and you develop on one machine and build on a different one, and the DLL file is only in the GAC of the build machine, the default behavior without the private node will cause the file to be copied correctly on the development machine, but not on the build machine.

The bigger problem is if the DLL file is not referenced directly, but the project references a second project that in turn references the DLL file. In that case, you cannot mark the DLL file to be "copy local" in the project, as it is not referenced by it. So if the DLL file exists in the GAC - it won't get copied to your output folder.

Possible solutions to this case are:

  • Uninstall the DLL file from the GAC
  • Add a direct reference to the DLL file in the end project(s)
  • Re-sign the DLL file with a new strong name, which will differentiate it from the DLL file in the GAC.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rzen
  • 21
  • 1
2

I was getting exactly the same issue. We have a Visual Studio 2008 project which references the EnterpriseLibrary. When we run our integrated build using TFS and our Web deployment project, all the DLL files are copied over. When we upgraded to Visual Studio 2010, TFS 2010 and WDP 2010, some of the DLL file's were missing. Strangely, this only occurs to some DLL files and not others.

For example, we get the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll copied in both cases, but not the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll.

As a workaround I copied the files accross using a "BeforeBuild" step.

It now seems to build OK.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

I am not sure how it was set up in Visual Studio 2008, but I am almost positive that you might have been using the Post-Build event command line. In there you can tell to copy the DLL files you need for deployment. An example is given below:

mkdir $(SolutionDir)\Deployment
copy "$(SolutionDir)Your_Library_Name\Your_Dll_ForDeployement.dll" 
$(SolutionDir)\Deployment\
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VoodooChild
  • 9,776
  • 8
  • 66
  • 99
0

I didn't meet the same problem but similar. I had WPF main project and referenced project where the referenced did not copy. I found that in my case the main project was set for NET 4.0 Client Profile and the referenced for NET 3.5. When I set the main project to 3.5 the compiled dll of the referenced project started to copy. (I don't know why because I solved it by practice)

Bronek
  • 10,722
  • 2
  • 45
  • 46
0

We can use the <Private>False</Private> to not to copy the referenced DLL files to the bin directory. This is useful when we are building applications in a separate TFS build server where we need to build the application and not to copy the DLL files to the bin directory.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jrapolu
  • 1
  • 2
0

Check the framework of the project in which the DLL file has been referenced. The framework should be .NET 4.0. Please correct it if the framework is Client Profile.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

I too ran into a similar issue where referenced dlls were not copied into the bin in published folder. I was using a TFS checked out copy that didn't include the bin folder into the application. -> So just included the bin folder. -> Built the referenced applications -> Published the website project Now I see all the referenced dlls in bin in the published folder

0

I had a similar issue with VS 2012 Express. I used Tesseract libraries in my project. Everything worked well until I used this project in a solution where were more than one project. Problem was that some DLLs (liblept168.dll, libtesseract302.dll) that are normally placed in folders bin/debug/x86 or bin/debug/x64 were copied only when I rebuilt whole solution. Changing a single line and building it again caused that the DLLs were deleted and not copied back.

I solved this issue by adding a reference of the project that creates missing DLLs to the startup project.

chviLadislav
  • 1,204
  • 13
  • 15
0

rzen and others, thanks - your comments led to a solution for us.

We have a project that targets version 10 of the Microsoft.ReportViewer.Common.dll and Microsoft.ReportViewer.WebForms.dll assemblies (separate "libs" folder we created at the 'src' level). But when we did a build, the output included version 12, which was recently installed on the build server.

Using comments here, we ensured that 'Copy Local' was set to True and that the flag was set in the project file. However, it was still deploying version 12. So what we found that did the trick was ensuring that the 'Specific Version' property was also set on the two references. Voila, version 10 of each file is now being deployed!

There was much rejoicing.

JH

John H
  • 1
0

If your project does not directly load the library, it won't always be deployed, even if it is referenced explicitly! I got confused because I could see it in a local Bin directory but not when deployed. The dll in the Bin directory was an old file that wasn't removed during Clean which is why I was confused.

A full clean and rebuild and it wasn't in my local Bin folder either which showed me the problem (I only use it in web.config). I then referenced the dll file itself in the project and set it to copy to output to make sure it gets deployed.

Lukos
  • 1,826
  • 1
  • 15
  • 29
0

Adding the parameter

/deployonbuild=false

to the msbuild command line fixed the issue.

Giles Roberts
  • 6,407
  • 6
  • 48
  • 63
0

Got a similar issue when upgrading old WebSites into WebApplications. The "Clean Solution" command would wipe out all external DLL files I purposely left in my bin folders.

Besides, it was not possible to bring those DLL back automatically simply by referencing them all, since many of them have the same file name (it happens when you work with many language specific resources)

Like stevie_c did, I took advantage of the Pre-Build command, but made it simpler:

I just used a xcopy command in the Pre-Build operation of the WebApplication project's properties. This way I could bring over the necessary external DLL files just before the build would start.

Christian
  • 88
  • 1
  • 6