MSBuild doesn't copy references (DLL files) if using project dependencies in solution

前端 未结 19 1261
Happy的楠姐
Happy的楠姐 2020-11-22 07:24

I have four projects in my Visual Studio solution (everyone targeting .NET 3.5) - for my problem only these two are important:

  1. MyBaseProject &
相关标签:
19条回答
  • 2020-11-22 07:49

    Another scenario where this shows up is if you are using the older "Web Site" project type in Visual Studio. For that project type, it is unable to reference .dlls that are outside of it's own directory structure (current folder and down). So in the answer above, let's say your directory structure looks like this:

    Where ProjectX and ProjectY are parent/child directories, and ProjectX references A.dll which in turn references B.dll, and B.dll is outside the directory structure, such as in a Nuget package on the root (Packages), then A.dll will be included, but B.dll will not.

    0 讨论(0)
  • 2020-11-22 07:50

    I just ran into a very similar issue. When compiling using Visual Studio 2010, the DLL file was included in the bin folder. But when compiling using MSBuild the third-party DLL file 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.

    0 讨论(0)
  • 2020-11-22 07:51

    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.

    0 讨论(0)
  • 2020-11-22 07:51

    Using Visual Studio 2015 adding the additional parameter

    /deployonbuild=false

    to the msbuild command line fixed the issue.

    0 讨论(0)
  • 2020-11-22 07:52

    I just had the exact same problem and it turned out to be caused by the fact that 2 projects in the same solution were referencing a different version of the 3rd party library.

    Once I corrected all the references everything worked perfectly.

    0 讨论(0)
  • 2020-11-22 07:58

    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.

    0 讨论(0)
提交回复
热议问题