Visual Studio - How to remove a reference in Release mode

后端 未结 5 2268
谎友^
谎友^ 2021-02-12 15:02

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

相关标签:
5条回答
  • 2021-02-12 15:38

    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.

    0 讨论(0)
  • 2021-02-12 15:52

    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.

    0 讨论(0)
  • 2021-02-12 15:54

    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.

    0 讨论(0)
  • 2021-02-12 15:56

    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

    0 讨论(0)
  • 2021-02-12 16:02

    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

    0 讨论(0)
提交回复
热议问题