Msbuild doesn’t copy references (dlls) if using project dependencies in solution RRS feed

  • Question

  • Hi,

    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 -

    If i run the build in visual studio 2008 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 loca l" in VS):

        <Reference Include="Elmah, Version=1.0.11211.0, Culture=neutral, processorArchitecture=MSIL">

    (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!)

    Please help. I get mad on this!

    Thanks, tobi

    P.S. I'm using Vista32bit with all latest updates, same goes for .net framework 1.1, 2.0, 3.0 and 3.5 (sp1)!
    • Edited by toebens2 Thursday, July 16, 2009 9:47 AM format2
    Thursday, July 16, 2009 9:41 AM

All replies

  • Hi,
    i read on another thread about msbuild in this forum that was posted back in 2006 already:

    In short: There it says that MyBaseProject needs some code that is referencing something from the elmah.dll. So i added this method in it:
    public void DummyMethodToReferenceElmah()
    			Elmah.ErrorSignal.FromCurrentContext().Raise(new ApplicationException("DummyMethodToReferenceElmah"));

    If i now build with msbuild the elmah.dll is also copied to the MyWebProject1's bin!

    Visual Studio 2008's behaviour seems to be still different for dll references than Msbuild's behaviour.

    Can you MSBUILD guys please fix it!??

    I don't want to add a referencing code in MyBaseProject at all just to make that happen via msbuild - VS also comes along without it!

    JFYI: MyBaseProject contains some basic classes - i.e. a BasePage from which every page in MyWebProject1 inherits. In MyWebProject1 only the web.config is used to switch the elmah handlers / modules on.
    (Many other WebProjects are referencing my MyBaseProject (i.e. MyWebProject2 to 99))

    thanks, tobi
    Thursday, July 16, 2009 10:29 AM
  • I found the same issue you describe with the Copy Local flag. You can see my findings in my blog post:

    Wednesday, September 16, 2009 9:00 AM
  • I have a similar problem with file (assembly) references from a web app project.
    VS 2008 correctly keeps the local copy of the referenced assembly up to date (in the bin folder), while MSBuild only updates the assembly if it is missing.  Since the default "Clean" target doesn't remove these copied assemblies, I have to manually clear the bin folder of such local copies.

    Making sure <Private> is true doesn't help. 
    Monday, March 1, 2010 12:52 PM
  • So... this is still happening in Visual Studio 2013? Hoping there's a better fix than "Add dummy code" or "Use Post-build to copy manually" yet? This is a legitimate issue when using dynamic execution of referenced code,. I am having this issue simply because I am leveraging IoC, which is a well known practice by now.

    Anybody from MS?


    Friday, August 8, 2014 4:24 PM
  • Funny is that when using a 3rd party dll in XAML only (WPF app) not in c# code, it seems like it is not recognized as 'used reference'... smells like a bug to me.

    I'd like a comment from Microsoft team as well.

    Sunday, August 30, 2015 3:44 PM
  • Still happening in VS2015 as well.
    Wednesday, June 22, 2016 4:19 PM
  • Still happening in VS2017 as well...
    Tuesday, July 11, 2017 11:06 AM
  • Still happening in VS2019 as well...
    Saturday, April 13, 2019 11:24 AM