Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding debug and release versions of libraries to a VS solution

I have my solution laid out as follows

src/Project1
src/Project2
src/Project...
bin/*.{dll,exe}
lib/Debug/*.dll
lib/Release/*.dll

All of the projects are set to build to the top level bin dir. I include a number of 3rd party library dependencies in the lib folder, I like having them here as they then get versioned along with the software in the source repo.

Normally I have each project add a reference to the Debug versions of the libraries but when it comes to releasing I have to manually change all the references to point to the Release versions.

My question is, is there a way to have Visual Studio automatically pick the DLL based on the build configuration?

like image 473
chillitom Avatar asked Dec 14 '22 00:12

chillitom


2 Answers

I suppose you are talking about C#? In that case you can manually adjust the project file to reference the correct library like this:

<Reference Include="Debug\XXX" Condition="'$(Configuration)'=='Debug'"/>
<Reference Include="Release\XXX" Condition="'$(Configuration)'=='Platform'"/>

or if the directory names match the config names exaclty you can even do:

<Reference Include="$(Configuration)\XXX"/>

and if needed you can also pull in the platform names the same way

like image 181
stijn Avatar answered Apr 13 '23 00:04

stijn


Modify the MSBuild settings in your project file and add conditions to the references. Like so:

<Reference Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <HintPath>D:\debug\libdll</HintPath>
</Reference>
<Reference Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <HintPath>D:\release\lib.dll</HintPath>
</Reference>
  • To edit the project file first unload it and then press edit proj file.

Some reference info:

  • MSDN msbuild
  • Tigris msbuild tasks
like image 28
Ralf de Kleine Avatar answered Apr 13 '23 00:04

Ralf de Kleine