Problem
A user reported an issue with the Rider IDE where it incorrectly determines that a using statement is not required when running the application in DEBUG mode. The using statement in question is actually required when the application is built in RELEASE mode, causing the build to fail in the user's Azure DevOps pipeline when the 'remove unused using statements' refactoring action is applied.
Cause
This issue arises because Rider (or the ReSharper backend) treats inactive preprocessor branches as inline comments. As a result, code refactoring actions may lead to incorrect results.
Resolution
While JetBrains has escalated this issue and is working on a resolution, there is no ETA for a fix. In the meantime, if your using statement is only used inside an inactive branch, you can enclose this using statement in a #if construction with the same condition. This workaround can help suppress the false positive warnings.
For example:
#if DEBUG
using Microsoft.Extensions.Logging;
options.EnableSensitiveDataLogging();
#else
using Microsoft.Extensions.Logging;
options.LogTo(System.Console.WriteLine, LogLevel.None);
#endif
This will ensure that the using statement is only considered 'unused' when the corresponding preprocessor branch is inactive, preventing the build failure in RELEASE mode.
Comments
0 comments
Please sign in to leave a comment.