Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio - How to remove a reference in Release mode

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,

like image 476
Razor Avatar asked Nov 04 '08 00:11

Razor


People also ask

How do I change the release mode in Visual Studio?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).

What is the difference between debug and release mode in Visual Studio?

By default, Debug includes debug information in the compiled files (allowing easy debugging) while Release usually has optimizations enabled. As far as conditional compilation goes, they each define different symbols that can be checked in your program, but they are language-specific macros.

How do I enable references in Visual Studio?

Restart Visual Studio, create a new C# UWP app project, and then right-click on the project and choose Add Reference.

What is debug mode and release mode?

Debug Mode: In debug mode the application will be slow. Release Mode: In release mode the application will be faster. Debug Symbols. Debug Mode: In the debug mode code, which is under the debug, symbols will be executed. Release Mode: In release mode code, which is under the debug, symbols will not be executed.


2 Answers

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

like image 101
Sander Rijken Avatar answered Sep 28 '22 06:09

Sander Rijken


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.

like image 44
Lou Franco Avatar answered Sep 28 '22 06:09

Lou Franco