views:

996

answers:

6

Hi,

I'm developing a library for use in other apps and this library has lots of debugging and logging statements thanks to NLog.

Is it possible to exclude the reference to NLog.dll when I switch to release mode?

Cheers,

+1  A: 

I'm not sure if there is a way you can have a reference in debug mode and exclude that reference once you switch to release mode.

If there's any way you could do this, it would be great, but I don't know any.

Nelson Reis
A: 

I can't think of a good way to do this. Unless maybe you wrote a stub reference for NLog.dll. Since you are using the reference in your code I don't see how you could just remove it in your release.

Probably too late now but in the future you could write a class to wrap NLog.dll and then just change it in one place so it wouldn't actually log in the release version. Or have some sort of flag.

wonderchook
Well if you add code in the #if DEBUG then they are excluded when compiling in Release mode
Sir Psycho
+1  A: 

The only way I know is to take the reference out completely and call the assembly via reflection. Then, you should only log if the assembly loads.

Lou Franco
A: 

There is no reason for removing a reference in case you are sure that no code will be in use from that DLL. In that case you can simply remove DLL.

Mash
A: 

Why would you want to do that?

If you want to stop logging, you can programatically turn off the logging. The performance hit will be minimal. (I have had great success with NLog even when logging cross process.)

Otherwise, you need to wrap it as described above.

-Scott

Scott P
+13  A: 

You can manually edit the csproj file, and do something like this:

<Reference Include="NLog" Condition="'$(Configuration)' == 'Debug'" />

This only makes it reference that assembly in Debug. I wouldn't recommend doing this often though, because this behavior isn't reflected in the references list in Visual Studio when you change the configuration. It does work when compiling though

Sander Rijken
I think you can force VS if you unload and reload once you've switched targets.
Preet Sangha
I use this method extensively and it is very useful. Unfortunately, Visual Studio will generate a warning about the "disabled" reference. Nevertheless, this allows for very important scenarios such as referencing different files in 64-bit builds and 32-bit builds.
Sander