How to stop VS from removing "unused" namespaces if they are actually used in preprocessor directives?

Viewed 141

I'm using Visual Studios Code Cleanup on Save to automatically clean my code when i save. It also removes unused namespaces. But now i noticed that it even removes namespaces when they are actually in use in preprocessor directives. What can i do to avoid it?

enter image description here

Code is here:

    private void RegisterTracking()
    {
#if DEBUG
        IResourceFilePostProcessor processor = null;
#else
        IResourceFilePostProcessor processor = new ResourceFilePostProcessor();
#endif
        For<ITrackingResourceFileService>().Add(new TrackingResourceFileService(processor));
    }    

Actually i think this is a visual studio bug because it should not be seen as unused.

1 Answers

Putting the using in a preprocessor directive seems to work.

#if !DEBUG
using xyz.EpiServer.Core.Tracking;
#endif
Related