Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i had a look on many similar questions on this side but none of them answered the question to my problem. The whole day i tried to solve this by finding a solution (via google etc.):

I have 4 projects in my VS solution (everyone targeting .net 3.5) - for my problem only these two are important:

  1. MyBaseProject <- this class library references a 3rd party dll (elmah.dll)
  2. MyWebProject1 <- this web application project has a reference to MyBaseProject

I added the elmah.dll reference to MyBaseProject in Visual studio 2008 by clicking "Add reference..." -> "Browse" tab -> selecting the "elmah.dll".

The Properties of the Elmah Reference are as follows:

  • Aliases - global
  • Copy local - true
  • Culture -
  • Description - Error Logging Modules and Handlers (ELMAH) for ASP.NET
  • File Type - Assembly
  • Path - D:\webs\otherfolder\_myPath\__tools\elmah\Elmah.dll
  • Resolved - True
  • Runtime version - v2.0.50727
  • Specified version - false
  • Strong Name - false
  • Version - 1.0.11211.0

In MyWebProject1 i added the reference to Project MyBaseProject by: "Add reference..." -> "Projects" tab -> selecting the "MyBaseProject". The Properties of this reference are the same except the following members:

  • Description -
  • Path - D:\webs\CMS\MyBaseProject\bin\Debug\MyBaseProject.dll
  • Version - 1.0.0.0

If i run the build in visual studio the elmah.dll is copied to my MyWebProject1's bin directory, along with MyBaseProject.dll!

However if i clean and run msbuild for the solution (via D:\webs\CMS>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /t:ReBuild /p:Configuration=Debug MyProject.sln) the elmah.dll is missing in MyWebProject1's bin directory - although the build itself contains no warning or errors!

I already made sure that the .csproj of MyBaseProject contains the private element with the value "true" (that should be an alias for "copy local" in VS):

<Reference Include="Elmah, Version=1.0.11211.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\mypath\__tools\elmah\Elmah.dll</HintPath>
    **<Private>true</Private>**
</Reference>

(The private tag didn't appear in the .csproj's xml by default, although VS said "copy local" true. I switched "copy local" to false - saved - and set it back to true again - save!)

What is wrong with MSBUILD? How to get the (elmah.dll) reference copied to MyWebProject1's bin?

I do NOT want to add a postbuild copy action to every projects postbuild command! (Imagine i would have many projects depend on MyBaseProject!)

share|improve this question
I'd love to get a clearer answer for why this happens. – David Faivre Apr 27 '12 at 17:18
Take a look at the answer provided here – Anuroopa Shenoy Aug 22 '12 at 15:31
any final solution with full source code sample working about it ? – Kiquenet May 13 at 14:24

7 Answers

up vote 8 down vote accepted

Take a look at:

This msbuild forum thread i started

you will find my temp solution / workaround there!

(MyBaseProject needs some code that is referencing some classes (whatever) from the elmah.dll for elmah.dll being copied to MyWebProject1's bin!)

share|improve this answer

If you are not using the assembly directly in code then visual studio whilst trying to be helpful detects that it is not used and doesn't include it in the output. I'm not sure why you are seeing different behaviour between visual studio and msbuild. You could try setting the build output to diagnostic for both and compare the results see where it diverges.

As for your elmah.dll reference if you are not referencing it directly in code you could add it as an item to your project and set the Build Action to Content and the Copy to Output Directory to Always.

share|improve this answer
1  
+1 for your copy to Output Directory comment, if Elmah isn't being used in code, makes sense to copy as content. – Kit Roed Jul 26 '10 at 17:00
2  
Indeed it ignores assemblies that are not used, BUT one major thing to note, as of VS 2010 using assembly in XAML resource dictionaries is not considered as using assmebly by VS, so it will not copy it. – Alex Burtsev Oct 8 '11 at 5:54
1  

I just deal with it like this. Go to the properties of your reference and do this:

Set "Copy local = false"
Save
Set "Copy local = true"
Save

and that's it.

Visual Studio 2010 doesn't initially put: <private>True</private> in the reference tag and setting "copy local" to false causes it to create the tag. Afterwards it will set it to true and false accordingly.

share|improve this answer
4  
This was a godsend. Thank you for this! – Junto Nov 21 '11 at 15:09
This worked for me as well. The DLLs were not being copied when doing a TFS build, and this fixed it. – Martin Mar 6 '12 at 15:44
2  
This doesn't work for me. – David Faivre Apr 27 '12 at 17:18
1  
This worked for me in VS2008 - thanks! – sydneyos Jul 7 '12 at 17:47
2  
Didn't work for me with MSBuild 4 / VS2012. That is, I was able to update references to say <Private>true</Private> but it seemed to have no effect on MSBuild. In the end, I just added NuGet references to downlevel projects. – Michael Teper Jan 18 at 21:48
show 2 more comments

I had the same problem.

Check if the framework version of your project is the same of the framework version of the dll that you put on reference.

In my case, my client was compiled using "Framework 4 Client" and the DLL was in "Framework 4".

share|improve this answer

I had the same problem and the dll was a dynamically loaded reference. To solve the problem I have added an "using" with the namespace of the dll. Now the dll is copied in the output folder.

share|improve this answer

The issue I was facing was I have a project that is dependent on a library project. In order to build I was following these steps:

msbuild.exe myproject.vbproj /T:Rebuild
msbuild.exe myproject.vbproj /T:Package

That of course meant I was missing my library's dll files in bin and most importantly in the package zip file. I found this works perfectly:

msbuild.exe myproject.vbproj /T:Rebuild;Package

I have no idea why this work or why it didn't in the first place. But hope that helps.

share|improve this answer

I just ran into a very similar issue. When compiling using VS 2010, the dll was included in the bin. But when compiling using MsBuild the 3rd party dll was not included. Very frustrating. The way I solved it was to include the nuget reference to the package in my web project even though I'm not using it directly there.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.