dlldeploymentreferencevisual-studio-projectvisual-studio-setup

Why is my DLL reference getting set back to its previous setting?


I have an .EXE/.DLL pair that I need to keep in sync.

The .EXE has a reference to the DLL.

In practice, it seems like all I need to do is copy my latest DLL to the folder where the latest EXE lives to get the EXE to reference the correct DLL (the one sitting right there next to it) while it's running.

However, the .EXE project has to be updated to explicitly reference the new DLL any time I update the .EXE. I do this by:

Removing the old DLL reference from the EXE project
Adding back the reference, pointing to the location of the latest version of the DLL

Note: The .EXE compiles fine without these steps, but it won't run while referencing the old and living alongside the new.

The potential problem is, whenever I go back to the .EXE project, it has reverted back to referencing the old DLL -- not the one I most recently set it to reference! IOW, I remove version 1.3.3889.27538 with one Path, replacing it with version 1.4.0.8 in another path (the DLL project's output folder), and the .EXE compiles (and runs) fine, but then when I open the EXE project again, the DLL references version 1.3.3889.27538 of the DLL again, pointing to that version's path.

Is there some setting somewhere that is stubbornly reverting to the old DLL whenever I turn around?

I don't know if this is significant, but the "Copy Local" property of the DLL reference in the EXE project is set to "True"

UPDATE

NOTE: When I remove and then add back the DLL reference (to the latest version of the DLL) and then build the EXE, I have to select "OK" on a dialog that informs me, "An error occurred saving the project user options for file '.csdproj.user'

I then have to select the "Save" button in the "Save File As" dialog to save the project file. Once I select "Yes" to replace the already existing file, it then builds fine.

Que implica? Es importante o de nada?


Solution

  • When you add a reference to a 3-rd party class Library (DLL) to a .NET project, a corresponding line in a project config (.csproj or .vbproj) file appears. Along with other settings, that line specifies the assembly version of the referenced class library. For example:

    <Reference Include="Telerik.WinControls, Version=2015.1.225.40, Culture=neutral, PublicKeyToken=5bb2a467cbec794e, processorArchitecture=MSIL" />
    

    That means: if you update the version of the external 3-rd party library, you need to explicitly update the project reference as well.

    If you want your external class library to always point to the latest build, it has to be a Project Reference. In other words, you add a Class Library project to your Solution and then in your main project just add the reference to that project (DLL). This way you'll always get the latest dependent DLL in your output folder.

    But again, if you are working with a 3-rd party libraries, you have to explicitly update the project reference to point to the latest DLL.