Reference DLL file not copying to bin with deployment project, causing error

前端 未结 14 864
刺人心
刺人心 2020-12-04 09:23

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

相关标签:
14条回答
  • 2020-12-04 09:42

    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.

    0 讨论(0)
  • 2020-12-04 09:44

    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

    0 讨论(0)
  • 2020-12-04 09:44

    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.
    0 讨论(0)
  • 2020-12-04 09:45

    Adding the parameter

    /deployonbuild=false

    to the msbuild command line fixed the issue.

    0 讨论(0)
  • 2020-12-04 09:49

    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.

    0 讨论(0)
  • 2020-12-04 09:53

    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\
    
    0 讨论(0)
提交回复
热议问题