none
How to set different references in debug and release mode

    Question

  • Hi
    I have a C# application end a C# assembly. I can compile both in release and debug version. In the C# application I'd like to refer the release assembly version in release mode and the debug version for the debug.
    Is it possible? In VS 2005 you have just one list of references for both release and debug.
    Marco
    Wednesday, September 5, 2007 9:52 AM

Answers

  • If I understand the question I don't think you can do this because you are referencing a pre built assembly in a visual studio project so it will statically link to the assembly by file location (excluding the GAC).

     

    The eaiser way to achieve what you want is add the visual project for assembly to your existing visual studio solution and it will manage the release versus debug assembly version. But I guess you probably don't have the original code base and therefore don't have the visual project for the assembly, I know you could do this with a post build event in visual studio as long as the classes\interfaces (i.e. the contracts) are the same for the release and devug versions.

     

    examples of post build events:

     

    http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx

     

    HTH

     

    Ollie Riches

    Wednesday, September 5, 2007 11:00 AM
  • Add the project that builds your reference assembly to your solution and set a reference to it with Add Reference, Project tab.
    Wednesday, September 5, 2007 4:22 PM
    Moderator

All replies

  • If I understand the question I don't think you can do this because you are referencing a pre built assembly in a visual studio project so it will statically link to the assembly by file location (excluding the GAC).

     

    The eaiser way to achieve what you want is add the visual project for assembly to your existing visual studio solution and it will manage the release versus debug assembly version. But I guess you probably don't have the original code base and therefore don't have the visual project for the assembly, I know you could do this with a post build event in visual studio as long as the classes\interfaces (i.e. the contracts) are the same for the release and devug versions.

     

    examples of post build events:

     

    http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx

     

    HTH

     

    Ollie Riches

    Wednesday, September 5, 2007 11:00 AM
  • Add the project that builds your reference assembly to your solution and set a reference to it with Add Reference, Project tab.
    Wednesday, September 5, 2007 4:22 PM
    Moderator
  • Thanks for answers. I'm a little bit late on post my reply because I was out of office for some time.
    Anyway I cannot add the project to my solution because I don't have the project itself.
    I found out that in C++/CLI there's the preprocessor directive #using which can make the trick. But it's not available in C#. Is there something similar to #using in C#?
    Marco
    Thursday, September 13, 2007 12:27 PM
  • How can you compile to both Debug and Release mode if you don't have the project?  Why use Debug mode if you don't have the source code?  C# doesn't have an equivalent of #using, only Project + Add Reference.
    Thursday, September 13, 2007 12:35 PM
    Moderator
  • Thanks nobugz, I had the same problem, and that solved it.  Now my "Release" unit tests refer to the "Release" main assembly, and the "Debug" unit tests refer to the Debug assembly.

    Friday, December 28, 2007 3:45 PM
  • cg60611, how did you do this?
    Monday, December 15, 2008 2:57 PM
  • Hi,

    It is possible to do this in VS 2008. Build both the debug and release version of the C# library and place each one within a debug and release folder. You can also include pdbs in the debug folder for debugging support. The folder hierarchy for the c# library should look like:
    lib\debug\lib.dll (debug config)
    lib\debug\lib.pdb
    lib\release\lib.dll (release config)

    In the c# application, set a reference to the debug version. Now edit the project file in a text editor, locate the reference and edit the "hint path" element. Replace the word "debug" in the path with "$(ConfigurationName)". It should read <HintPath>...\lib\$(ConfigurationName)\lib.dll</HintPath>

    Now in the IDE when the C# app is in debug mode the reference points to the debug ver of the library and in release it uses the release version. If PDBs are included in the debug version, full debugging support is available.

    I haven't tried this is vs 2005.

    Brian
    • Proposed as answer by webJose Wednesday, October 14, 2009 10:15 PM
    Wednesday, October 14, 2009 11:50 AM
  • How do I do the same for a VC++.NET 2005 application? the .vcproj file looks a lot different from the .csproj file that is a part of the C# solution.

     

    Thanks.

    Friday, October 15, 2010 8:25 PM
  • In VS 2010 I believe you can add the following to the reference entry in your project, if the debug and release versions of the assemblies you want to use are co-located in the same directory with different names:

    <HintPath Condition="'$(Configuration)'=='Debug'">C:\some\assembly\location\SomeAssembly.Debug.dll</HintPath>      <HintPath Condition="'$(Configuration)'=='Release'">C:\some\assembly\location\SomeAssembly.Release.dll</HintPath>

     



    • Edited by PurpleFoofy Friday, December 2, 2011 2:56 PM
    • Proposed as answer by Dave Bakin Monday, January 6, 2014 11:26 PM
    Thursday, December 1, 2011 11:49 PM
  • Excellent!  Remarkable that this isn't supported in the UI.
    Monday, January 6, 2014 11:27 PM