Open stephentoub opened 5 years ago
Bump, just happened to me
I just went to file this issue after getting hit by it, and discovered I already did over two years ago :)
There is another related scenario.
Steps to reproduce:
#if NET6_0
namespace ConsoleApp
{
using System;
internal class Class1
{
public void M()
{
Console.WriteLine("");
}
}
}
#endif
Actual Behavior:
Applying the fix gives
using System;
#if NET6_0
namespace ConsoleApp
{
internal class Class1
{
public void M()
{
Console.WriteLine("");
}
}
}
#endif
It's less severe because the code still compiles but we end up with warnings about unused using when compiling in different target framework (which can cause build break because of TreatWarningsAsErrors
).
Expected Behavior:
Applying the fix gives
#if NET6_0
using System;
namespace ConsoleApp
{
internal class Class1
{
public void M()
{
Console.WriteLine("");
}
}
}
#endif
Related we ran into this on a project that multitargets net48 and net7.0
namespace MyNamespace;
using System;
#if NET6_0_OR_GREATER
using System.Linq;
#endif
public class MyClass { }
// results in
using System;
#if NET6_0_OR_GREATER
using System.Linq;
namespace MyNamespace;
#endif
public class MyClass { }
And it sometimes duplicates the namespace.
Version Used: 3.5.0-beta2-19570-07+4bd316035f64c9776d5420af71df8ba38e8e23e4
Steps to Reproduce: Create a project with this code:
Then apply IDE0065 when it fires on the
using System.Runtime.CompilerServices;
directive.Expected Behavior: Refactors to:
or doesn't offer the refactoring.
Actual Behavior: Refactors to:
which is broken and won't compile if that compilation constant is set.