views:

32

answers:

1

I have a large project which I am replacing 2 parts of with better open source alternatives. The open source libraries are pretty big but they are stable and unchanging so including the source in my VS project directly seems pointless to me - its more to load, more to compile etc. I would much rather just build the 2 open source projects alone, at a fixed version and then reference them from the main project.

But this gives me a couple of problems.

  1. I will want DEBUG and RELEASE versions of the libraries - VS has no way to switch between references based on those defines.

  2. Debugging is harder if I want to step into the code in the other projects - its not as simple as just stepping through the code - or is it?

  3. Something else I've not yet thought of...

So while I play around with ideas I thought I would ask how you guys would set it up.

The main project and the 2 open source projects are all in different SVN repositories. The Open source projects I will not be getting the new trunk every day, but fixing on a release.

Thanks

+4  A: 

1) You can switch between references for different build configurations if you do it manually by editing the .csproj file.

The csproj file is an MSBuild script which is XML. If you browse down it you should find a <ItemGroup> element that contains a bunch of <Reference> elements. You can add a condition to one of these reference elements like this:

<Reference Condition=" '$(Configuration)' == 'Debug' " Include="System.Drawing" />

The Include attribute can contain the full strong name of the assembly, which may not necessarily be different for the debug and release builds of your binary. In which case, you can add a <HintPath> element to include the path to the .dll.

<Reference Include="assembly strong name">
  <HintPath>c:\LibraryStuff\Debug\Library.dll</HintPath>
</Reference>

Your hint path can also be relative:

<HintPath>..\..\LibraryStuff\Debug\Library.dll</HintPath>

[Disclaimer: I've never actually done this with references though, I can't guarantee there won't be issues. I quickly tested it out and it seems to work fine, although visual studio does display both the references no matter which build config you have selected (although it only builds the one for the matching config type). It also puts a warning icon on the second one if they have matching names, but the compile seems to work fine.]

If you do have problems, you could try just having one reference with two different HintPath nodes and putting the conditional on the hint path.


2) Provided you have the .pdbs and the source code all in the correct places and accessibly, you should just be able to debug straight through into the library by just stepping into the code even though you are only referencing the .dll file.

Simon P Stevens
1. interesting, I shall look into it2. problem with this is that I thought that there's differences between debug and release builds when you debug due to optimization etc. Thanks for the replies though.
Andy Dunn
Re: 2 - Provided the release build was made with full debugging symbols turned on (and as you have the source, you can do it yourself I suppose) then you should have no problem debugging into the library even in release mode. You won't be able to step every line, because of the optimisations like you say, but in general, debugging will still work fine.
Simon P Stevens