1

I have a simple VS project which references DLLs which must be specific to a version of the software I am integrating with and I need to release my project for multiple versions of the software - 2015 & 2016.

So I need to build MyProject2015.DLL and MyProject2016.DLL - let's pretend each must reference Application2015.DLL and Application2016.DLL for the sake of example. I want to maintain a single code base. I'm using Team Foundation Sever 2015 for version control. How can I achieve this?

2 Answers 2

2

With the assistance of a colleague I resolved this issue by using two projects which referenced the same classes but utilized different references.

First, I removed the project from the solution. I then copied the csproj file and renamed each with the version numbers:

  • myProject 2015.csproj
  • myProject 2016.csproj

Next I added each project back to the solution in VS. I like to keep a folder with referenced DLLs with the project so they are checked-in to TFS and another developer has the correct versions referenced when pulling down the project. So I created a v2015 and v2016 folder for the respective projects placing the appropriate DLLs in each. I then removed the existing references in the projects and re-added them, pointing to the files in the version-ed folders. Resulting project tree.

Now I still have two additional build configurations, one for each version. I made sure each mapped to version-ed bin folders (bin\2015 & bin\2016). I also added an AssemblyName tag in the csproj files so that my DLL for each build gets a name that includes the version number. Finally, in the Build Configuration Manager, I selected only the 2015 project for the 2015 build and likewise for the 2016 build. Here is the build config section of the csproj files.

Now, when I open a class in the 2015 project and then try to open the same class in the 2016 project, it opens the same class file in the IDE.

UPDATE 11/06/2019: I have been informed the visual studio project type of Shared Project is for exactly this scenario. I have created a new solution which has one shared project that holds all my classes. Then I have multiple class library projects for each version I need built. Each of these projects references the shared project and has its own references to each third party versioned DLL it utilizes. This solution has been much better suited to including a Unit Test project as well.

5
  • If it opens the same class file, how do you distinguish the code differences, if any, between each version? Commented Oct 6, 2017 at 15:59
  • I believe this is going to work (I'll need to get my 2016 environment set up to be certain). I defined a different compilation symbol on each project. Then, if necessary, I can place version specific code in #if #elif blocks. Commented Oct 6, 2017 at 16:40
  • Allow me to add that I do not presently expect my code to require differences based on the version. The libraries I reference are stable. However, if that turns out to be wrong in the future, I'm sure an analysis would take place as compiler directives are added to determine when two completely separate projects would be appropriate. Commented Oct 6, 2017 at 17:12
  • I've been reading Working Effectively with Legacy Code by Michael Feathers and I realize I write procedural code with no unit tests. So I tried adding a Unit Test project to this concept and it is not going well. I added a reference to my 2015 version project to the Unit Test project and tried to write a Test Method. I'm getting the "Could not load file or assembly" on one of the version dependent DLLs. Commented Mar 4, 2019 at 3:30
  • The previously mentioned "FileNotFoundException" is specific to the application with which I am integrating - Dynamics GP. It was resolved thanks to Tim Wappat's blog post: timwappat.info/post/2017/04/18/… Commented Oct 28, 2019 at 22:12
0

I had to do something similar with 32 bit and 64 bit builds

You can setup you project file to use different references based on build configuration

http://mikaelkoskinen.net/post/changing-project-s-references-based-on-the-build-configuration

Then you can run the build in build configuration X on your build server to get the right output.

Its annoying that you have to build more than once to get one complete output (in my case a nuget package with both dlls) but you can cobble chains of stuff together in team city to make it all happen. Not sure about TFS

13
  • I have attempted this by making two folders in my project & including the different versions of the references DLLs in them. I have then create two new build configurations and added a custom tag for the location of the DLL. link The completed build for 2016 is still referencing the 2015 version of Application.Dynamics.DLL. I've used ILSpy on the built DLL to verify this. Could this be due to search order for references and the reference to the 2015 DLL is located before the HintPath is searched? Commented Oct 5, 2017 at 3:26
  • dont include both dlls in the final package, just the one you want Commented Oct 5, 2017 at 8:20
  • also, dont thet have different file names? sounds like there is a mistake in there somewhere Commented Oct 5, 2017 at 8:21
  • The files do not have different names for each version. GP 2015 vs GP 2016 I'm uncertain how I am doing this differently than your description or what you mean by your first comment. Here is the : Project tree in case that gives you a clue. What else can I provide that might help? Commented Oct 5, 2017 at 14:36
  • I mean if your bin folder doesnt contain both files it will be impossible to reference the wrong one Commented Oct 5, 2017 at 15:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.