diff --git a/.openpublishing.redirection.csharp.json b/.openpublishing.redirection.csharp.json index 298a406f1d4e6..56820abeb011c 100644 --- a/.openpublishing.redirection.csharp.json +++ b/.openpublishing.redirection.csharp.json @@ -151,6 +151,10 @@ "source_path_from_root": "/docs/csharp/lambda-expressions.md", "redirect_url": "/dotnet/csharp/language-reference/operators/lambda-expressions" }, + { + "source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs8892.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/warning-waves#cs8892" + }, { "source_path_from_root": "/docs/csharp/language-reference/compiler-options/addmodule-compiler-option.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-options/inputs" diff --git a/docs/csharp/language-reference/compiler-messages/cs8892.md b/docs/csharp/language-reference/compiler-messages/cs8892.md deleted file mode 100644 index 6b2571abd903f..0000000000000 --- a/docs/csharp/language-reference/compiler-messages/cs8892.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -description: "Learn more about: Compiler warning (level 5) CS8892" -title: "Compiler warning (level 5) CS8892" -ms.date: 08/26/2020 -f1_keywords: - - "CS8892" -helpviewer_keywords: - - "CS8892" -author: Youssef1313 ---- - -# Compiler warning (level 5) CS8892 - -Method 'method' will not be used as an entry point because a synchronous entry point 'method' was found. - -This warning is generated on all async entry point candidates when you have multiple valid entry points, where they contain one or more synchronous entry point and one or more asynchronous entry points. - -Because async main was only supported starting with C# 7.1, this warning isn't generated for projects targeting a previous version. - -> [!NOTE] -> The compiler always uses the synchronous entry point. In case there are multiple synchronous entry points, you get a compiler error. - -## Example - -The following example generates CS8892: - -```csharp -using System; -using System.Threading.Tasks; - -public class Program -{ - // CS8892: Method 'Program.Main()' will not be used as an entry point because a synchronous entry point 'Program.Main(string[])' was found. - public static async Task Main() - { - await Task.Delay(1); - } - - public static void Main(string[] args) - { - Console.WriteLine(2); - } -} -``` - -## How to fix this warning - -Keep only the intended entry point for your program, and rename the others. - -```csharp -using System; -using System.Threading.Tasks; - -public class Program -{ - public static async Task SomeOtherNameAsync() - { - await Task.Delay(1); - } - - public static void Main(string[] args) - { - Console.WriteLine(2); - } -} -``` diff --git a/docs/csharp/language-reference/compiler-messages/snippets/ImportedTypes/ImportedTypes.csproj b/docs/csharp/language-reference/compiler-messages/snippets/ImportedTypes/ImportedTypes.csproj new file mode 100644 index 0000000000000..132c02c59c236 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/snippets/ImportedTypes/ImportedTypes.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/docs/csharp/language-reference/compiler-messages/snippets/ImportedTypes/Types.cs b/docs/csharp/language-reference/compiler-messages/snippets/ImportedTypes/Types.cs new file mode 100644 index 0000000000000..534a79ce7c41a --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/snippets/ImportedTypes/Types.cs @@ -0,0 +1,9 @@ +namespace ImportedTypes; + +// +public struct Struct +{ + private string data = String.Empty; + public Struct() { } +} +// diff --git a/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/Program.cs b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/Program.cs new file mode 100644 index 0000000000000..6e89e1c139292 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/Program.cs @@ -0,0 +1,31 @@ +// See https://aka.ms/new-console-template for more information + +namespace WarningWaves; + +public static class Program +{ + // + public static void Main() + { + RunProgram(); + } + + // CS8892 + public static async Task Main(string[] args) + { + await RunProgramAsync(); + } + // + + private static void RunProgram() + { + WaveFive.Examples(); + } + + private static async Task RunProgramAsync() + { + RunProgram(); + await Task.Yield(); + } +} + diff --git a/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WarningWaves.csproj b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WarningWaves.csproj new file mode 100644 index 0000000000000..4494a6336e3c5 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WarningWaves.csproj @@ -0,0 +1,16 @@ + + + + enable + Exe + net7.0 + enable + 7 + preview + + + + + + + diff --git a/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WaveFive.cs b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WaveFive.cs new file mode 100644 index 0000000000000..5b80ceb43326d --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WaveFive.cs @@ -0,0 +1,200 @@ +using System; +using ImportedTypes; + +namespace WarningWaves; + +public class WaveFive +{ + public class Src + { + public bool Select(Func selector) => true; + } + + public class Src2 + { + public int Select(Func selector) => 0; + } + + public static void Examples() + { + var w = new WaveFive(); + + w.M(w); + + QueryExpression(); + QueryExpressionNoWarn(); + + } + + private static void QueryExpression() + { + // + bool b = true; + var source = new Src(); + b = true; + source = new Src(); + var a = b && from c in source select c; + Console.WriteLine(a); + + var indexes = new Src2(); + int[] array = { 1, 2, 3, 4, 5, 6, 7 }; + var range = array[0..from c in indexes select c]; + // + } + + private static void QueryExpressionNoWarn() + { + // + bool b = true; + var source = new Src(); + b = true; + source = new Src(); + var a = b && (from c in source select c); + Console.WriteLine(a); + + var indexes = new Src2(); + int[] array = { 1, 2, 3, 4, 5, 6, 7 }; + var range = array[0..(from c in indexes select c)]; + // + } + // + static class StaticClass + { + public static void Thing() { } + } + + void M(object o) + { + // warning: cannot use a static type in 'is' or 'as' + if (o is StaticClass) + { + Console.WriteLine("Can't happen"); + } + else + { + Console.WriteLine("o is not an instance of a static class"); + } + } + // + + // + class Program + { + public static void M(S s) + { + if (s == null) { } // CS8073: The result of the expression is always 'false' + if (s != null) { } // CS8073: The result of the expression is always 'true' + } + } + + struct S + { + public static bool operator ==(S s1, S s2) => s1.Equals(s2); + public static bool operator !=(S s1, S s2) => !s1.Equals(s2); + public override bool Equals(object? other) + { + // Implementation elided + return false; + } + public override int GetHashCode() => 0; + + // Other details elided... + } + // + + // + public static class Utilities + { + // elided + } + + public interface IUtility + { + // CS8897 + public void SetUtility(Utilities u); + + // CS8898 + public Utilities GetUtility(); + } + // + + + // + public struct DefiniteAssignmentWarnings + { + // CS8880 + public Struct Property { get; } + // CS8881 + private Struct field; + + // CS8882 + public void Method(out Struct s) + { + + } + + public DefiniteAssignmentWarnings(int dummy) + { + // CS8883 + Struct v2 = Property; + // CS8884 + Struct v3 = field; + // CS8885: + DefiniteAssignmentWarnings p2 = this; + } + + public static void Method2(out Struct s1) + { + // CS8886 + var s2 = s1; + s1 = default; + } + + public static void UseLocalStruct() + { + Struct r1; + var r2 = r1; + } + } + // + + + // + public struct DefiniteAssignmentNoWarnings + { + // CS8880 + public Struct Property { get; } = default; + // CS8881 + private Struct field = default; + + // CS8882 + public void Method(out Struct s) + { + s = default; + } + + public DefiniteAssignmentNoWarnings(int dummy) + { + // CS8883 + Struct v2 = Property; + // CS8884 + Struct v3 = field; + // CS8885: + DefiniteAssignmentNoWarnings p2 = this; + } + + public static void Method2(out Struct s1) + { + // CS8886 + s1 = default; + var s2 = s1; + } + + public static void UseLocalStruct() + { + Struct r1 = default; + var r2 = r1; + } + } + // +} diff --git a/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WaveSeven.cs b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WaveSeven.cs new file mode 100644 index 0000000000000..fa8f3498e214b --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WaveSeven.cs @@ -0,0 +1,7 @@ +namespace WarningWaves; + +// +public class lowercasename +{ +} +// diff --git a/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WaveSix.cs b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WaveSix.cs new file mode 100644 index 0000000000000..5c800289b479b --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/snippets/WarningWaves/WaveSix.cs @@ -0,0 +1,44 @@ +namespace WarningWaves; +public class WaveSix +{ + // + public partial class PartialType + { + public partial void M1(int x); + + public partial T M2(string s) where T : struct; + + public partial void M3(string s); + + + public partial void M4(object o); + public partial void M5(dynamic o); + public partial void M6(string? s); + } + // + + // + public partial class PartialType + { + // Different parameter names: + public partial void M1(int y) { } + + // Different type parameter names: + public partial TResult M2(string s) where TResult : struct => default; + + // Relaxed nullability + public partial void M3(string? s) { } + + + // Mixing object and dynamic + public partial void M4(dynamic o) { } + + // Mixing object and dynamic + public partial void M5(object o) { } + + // Note: This generates CS8611 (nullability mismatch) not CS8826 + public partial void M6(string s) { } + } + // + +} diff --git a/docs/csharp/language-reference/compiler-messages/warning-waves.md b/docs/csharp/language-reference/compiler-messages/warning-waves.md new file mode 100644 index 0000000000000..7296949914f91 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/warning-waves.md @@ -0,0 +1,165 @@ +--- +title: "C# Compiler warning waves" +description: "C# warning waves are optional warnings that can be reported on code where previously a warning wouldn't have been reported. They represent practices that could be harmful, or potentially elements that may be breaking changes in the future." +ms.date: 05/11/2022 +f1_keywords: + - "CS7023" + - "CS8073" + - "CS8848" + - "CS8880" + - "CS8881" + - "CS8882" + - "CS8883" + - "CS8884" + - "CS8885" + - "CS8886" + - "CS8887" + - "CS8892" + - "CS8897" + - "CS8898" + - "CS8826" + - "CS8981" +helpviewer_keywords: + - "CS7023" + - "CS8073" + - "CS8848" + - "CS8880" + - "CS8881" + - "CS8882" + - "CS8883" + - "CS8884" + - "CS8885" + - "CS8886" + - "CS8887" + - "CS8892" + - "CS8897" + - "CS8898" + - "CS8826" + - "CS8981" +--- +# C# Warning waves + +New warnings and errors may be introduced in each release of the C# compiler. When new warnings could be reported on existing code, those warnings are introduced under an opt-in system referred to as a *warning wave*. The opt-in system means that you shouldn't see new warnings on existing code without taking action to enable them. Warning waves are enabled using the [**AnalysisLevel**](../compiler-options/errors-warnings.md#analysis-level) element in your project file. When `true` is specified, enabled warning wave warnings generate errors. Warning wave 5 diagnostics were added in C# 9. Warning wave 6 diagnostics were added in C# 10. Warning wave 7 diagnostics were added in C# 11. + +## CS8981 - The type name only contains lower-cased ascii characters. + +*Warning wave 7* + +Any new keywords added for C# will be all lower-case ASCII characters. This warning ensures that none of your types conflict with future keywords. The following code produces CS8981: + +:::code language="csharp" source="./snippets/WarningWaves/WaveSeven.cs" id="NoLowercaseTypes"::: + +You can address this warning by renaming the type to include at least one non-lower case ASCII character, such as an upper case character, a digit, or an underscore. + +## CS8826 - Partial method declarations have signature differences. + +*Warning wave 6* + +This warning corrects some inconsistencies in reporting differences between partial method signatures. The compiler always reported an error when the partial method signatures created different CLR signatures. Now, the compiler reports CS8826 when the signatures are syntactically different C#. Consider the following partial class: + +:::code language="csharp" source="./snippets/WarningWaves/WaveSix.cs" id="PartialMethodDeclaration"::: + +The following partial class implementation generates several examples of CS8626: + +:::code language="csharp" source="./snippets/WarningWaves/WaveSix.cs" id="PartialMethodDefinition"::: + +> [!NOTE] +> If the implementation of a method uses a non-nullable reference type when the other declaration accepts nullable reference types, CS8611 is generated instead of CS8826. + +To fix any instance of these warnings, ensure the two signatures match. + +## CS7023 - A static type is used in an 'is' or 'as' expression. + +*Warning wave 5* + +The `is` and `as` expressions always return `false` for a static type because you can't create instances of a static type. The following code produces CS7023: + +:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="StaticTypeAsIs"::: + +The compiler reports this warning because the type test can never succeed. To correct this warning, remove the test and remove any code executed only if the test succeeded. In the preceding example, the `else` clause is always executed. The method body could be replaced by that single line: + +```csharp +Console.WriteLine("o is not an instance of a static class"); +``` + +## CS8073 - The result of the expression is always 'false' (or 'true'). + +*Warning wave 5* + +The `==` and `!=` operators always return `false` (or `true`) when comparing an instance of a `struct` type to `null`. The following code demonstrates this warning. Assume `S` is a `struct` that has defined `operator ==` and `operator !=`: + +:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="StructsArentNull"::: + +To fix this error, remove the null check and code that would execute if the object is `null`. + +## CS8848 - Operator 'from' can't be used here due to precedence. Use parentheses to disambiguate. + +*Warning wave 5* + +The following examples demonstrate this warning. The expression binds incorrectly because of the precedence of the operators. + +:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="QueryPrecedence"::: + +To fix this error, put parentheses around the query expression: + +:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="QueryPrecedenceNoWarn"::: + +## Members must be fully assigned, use of unassigned variable (CS8880, CS8881, CS8882, CS8883, CS8884, CS8885, CS8886, CS8887) + +*Warning wave 5* + +Several warnings improve the definite assignment analysis for `struct` types declared in imported assemblies. All these new warnings are generated when a struct in an imported assembly includes an inaccessible field (usually a `private` field) of a reference type, as shown in the following example: + +:::code language="csharp" source="snippets/ImportedTypes/Types.cs" id="DeclareImportedType"::: + +The following examples show the warnings generated from the improved definite assignment analysis: + +- CS8880: Auto-implemented property 'Property' must be fully assigned before control is returned to the caller. +- CS8881: Field 'field' must be fully assigned before control is returned to the caller. +- CS8882: The out parameter 'parameter' must be assigned to before control leaves the current method. +- CS8883: Use of possibly unassigned auto-implemented property 'Property'. +- CS8884: Use of possibly unassigned field 'Field' +- CS8885: The 'this' object can't be used before all its fields have been assigned. +- CS8886: Use of unassigned output parameter 'parameterName'. +- CS8887: Use of unassigned local variable 'variableName' + +:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="DefiniteAssignmentWarnings"::: + +You can fix any of these warnings by initializing or assigning the imported struct to its default value: + +:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="DefiniteAssignment"::: + +## CS8892 - Method will not be used as an entry point because a synchronous entry point 'method' was found. + +*Warning wave 5* + +This warning is generated on all async entry point candidates when you have multiple valid entry points, including one or more synchronous entry point. Because async main was only supported starting with C# 7.1, this warning isn't generated for projects targeting a previous version. + +The following example generates CS8892: + +:::code language="csharp" source="./snippets/WarningWaves/Program.cs" id="MultipleEntryPoints"::: + +> [!NOTE] +> The compiler always uses the synchronous entry point. In case there are multiple synchronous entry points, you get a compiler error. + +To fix this warning, remove or rename the asynchronous entry point. + +## CS8897 - Static types can't be used as parameters + +*Warning wave 5* + +Members of an interface can't declare parameters whose type is a static class. The following code demonstrates both CS8897 and CS8898: + +:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="StaticTypeInInterface"::: + +To fix this warning, change the parameter type or remove the method. + +## CS8898 - static types can't be used as return types + +*Warning wave 5* + +Members of an interface can't declare a return type that is a static class. The following code demonstrates both CS8897 and CS8898: + +:::code language="csharp" source="./snippets/WarningWaves/WaveFive.cs" id="StaticTypeInInterface"::: + +To fix this warning, change the return type or remove the method. diff --git a/docs/csharp/language-reference/compiler-options/errors-warnings.md b/docs/csharp/language-reference/compiler-options/errors-warnings.md index 79b945cfd10c5..62a19158527a7 100644 --- a/docs/csharp/language-reference/compiler-options/errors-warnings.md +++ b/docs/csharp/language-reference/compiler-options/errors-warnings.md @@ -1,7 +1,7 @@ --- description: "C# Compiler Options for errors and warnings. These options suppress or enable warnings, and control warnings as errors." title: "C# Compiler Options - errors and warnings" -ms.date: 03/12/2021 +ms.date: 05/11/2022 f1_keywords: - "cs.build.options" helpviewer_keywords: @@ -19,6 +19,7 @@ helpviewer_keywords: The following options control how the compiler reports errors and warnings. The new MSBuild syntax is shown in **Bold**. The older *csc.exe* syntax is shown in `code style`. - **WarningLevel** / `-warn`: Set warning level. +- **AnalysisLevel**: Set optional warning level. - **TreatWarningsAsErrors** / `-warnaserror`: Treat all warnings as errors - **WarningsAsErrors** / `-warnaserror`: Treat one or more warnings as errors - **WarningsNotAsErrors** / `-warnnotaserror`: Treat one or more warnings not as errors @@ -37,17 +38,31 @@ The **WarningLevel** option specifies the warning level for the compiler to disp The element value is the warning level you want displayed for the compilation: Lower numbers show only high severity warnings. Higher numbers show more warnings. The value must be zero or a positive integer: -|Warning level|Meaning| -|-------------------|-------------| -|0|Turns off emission of all warning messages.| -|1|Displays severe warning messages.| -|2|Displays level 1 warnings plus certain, less-severe warnings, such as warnings about hiding class members.| -|3|Displays level 2 warnings plus certain, less-severe warnings, such as warnings about expressions that always evaluate to `true` or `false`.| -|4 (the default)|Displays all level 3 warnings plus informational warnings.| -|Greater than 4|Displays warnings with the specified value and all less-severe warnings. For more information, see [additional warnings](https://github.com/dotnet/roslyn/blob/main/docs/compilers/CSharp/Warnversion%20Warning%20Waves.md).| +| Warning level | Meaning | +|---------------|---------| +| 0 | Turns off emission of all warning messages. | +| 1 | Displays severe warning messages. | +| 2 | Displays level 1 warnings plus certain, less-severe warnings, such as warnings about hiding class members. | +| 3 | Displays level 2 warnings plus certain, less-severe warnings, such as warnings about expressions that always evaluate to `true` or `false`. | +| 4 (the default)|Displays all level 3 warnings plus informational warnings. | -> [!NOTE] -> To make sure you always have all warnings if the compiler is updated with new warning levels, put an arbitrary large value (for example, `9999`). +> [!WARNING] +> The compiler command line accepts values greater than 4 to enable [warning wave warnings](../compiler-messages/warning-waves.md). However, the .NET SDK sets the *WarningLevel* to match the *AnalysisLevel* in your project file. + +To get information about an error or warning, you can look up the error code in the [Help Index](/visualstudio/help-viewer/install-manage-local-content). For other ways to get information about an error or warning, see [C# Compiler Errors](../compiler-messages/index.md). Use [**TreatWarningsAsErrors**](#treatwarningsaserrors) to treat all warnings as errors. Use [**DisabledWarnings**](#disabledwarnings) to disable certain warnings. + +## Analysis level + +| Analysis level | Meaning | +|------------------|---------| +| 5 | Displays all optional [warning wave 5 warnings](../compiler-messages/warning-waves.md#cs7023---a-static-type-is-used-in-an-is-or-as-expression). | +| 6 | Displays all optional [warning wave 6 warnings](../compiler-messages/warning-waves.md#cs8826---partial-method-declarations-have-signature-differences). | +| 7 | Displays all optional [warning wave 7 warnings](../compiler-messages/warning-waves.md#cs8981---the-type-name-only-contains-lower-cased-ascii-characters). | +| latest (default) | Displays all informational warnings up to and including the current release. | +| preview | Displays all informational warnings up to and including the latest preview release. | +| none | Turns off all informational warnings. | + +For more information on optional warnings, see [Warning waves](../compiler-messages/warning-waves.md). To get information about an error or warning, you can look up the error code in the Help Index. For other ways to get information about an error or warning, see [C# Compiler Errors](../compiler-messages/index.md). Use [**TreatWarningsAsErrors**](#treatwarningsaserrors) to treat all warnings as errors. Use [**DisabledWarnings**](#disabledwarnings) to disable certain warnings. @@ -61,20 +76,23 @@ The **TreatWarningsAsErrors** option treats all warnings as errors. You can also All warning messages are instead reported as errors. The build process halts (no output files are built). By default, **TreatWarningsAsErrors** isn't in effect, which means warnings don't prevent the generation of an output file. Optionally, if you want only a few specific warnings to be treated as errors, you may specify a comma-separated list of warning numbers to treat as errors. The set of all nullability warnings can be specified with the [**Nullable**](language.md#nullable) shorthand. Use [**WarningLevel**](#warninglevel) to specify the level of warnings that you want the compiler to display. Use [**DisabledWarnings**](#disabledwarnings) to disable certain warnings. +> [!IMPORTANT] +> There are two subtle differences between using the `` element in your *csproj* file, and using the `warnaserror` MSBuild command line switch. *TreatWarningsAsErrors* only impacts the C# compiler, not any other MSBuild tasks in your *csproj* file. The `warnaserror` command line switch impacts all tasks. Secondly, the compiler doesn't produce any output on any warnings when *TreatWarningsAsErrors* is used. The compiler produces output when the `warnaserror` command line switch is used. + ## WarningsAsErrors and WarningsNotAsErrors -The **WarningsAsErrors** and **WarningsNotAsErrors** options override the **TreatWarningsAsErrors** option for a list of warnings. +The **WarningsAsErrors** and **WarningsNotAsErrors** options override the **TreatWarningsAsErrors** option for a list of warnings. This option can be used with all *CS* warnings. The "CS" prefix is optional. You can use either the number, or "CS" followed by the error or warning level. For other elements that affect warnings, see the [Common MSBuild properties](/visualstudio/msbuild/common-msbuild-project-properties). Enable warnings 0219 and 0168 as errors: ```xml -0219,0168 +0219,CS0168 ``` Disable the same warnings as errors: ```xml -0219,0168 +0219,CS0168 ``` You use **WarningsAsErrors** to configure a set of warnings as errors. Use **WarningsNotAsErrors** to configure a set of warnings that should not be errors when you've set all warnings as errors. @@ -89,7 +107,7 @@ The **DisabledWarnings** option lets you suppress the compiler from displaying o `number1`, `number2` Warning number(s) that you want the compiler to suppress. You specify the numeric part of the warning identifier. For example, if you want to suppress *CS0028*, you could specify `28`. The compiler silently ignores warning numbers passed to **DisabledWarnings** that were valid in previous releases, but that have been removed. For example, *CS0679* was valid in the compiler in Visual Studio .NET 2002 but was removed later. - The following warnings cannot be suppressed by the **DisabledWarnings** option: + The following warnings can't be suppressed by the **DisabledWarnings** option: - Compiler Warning (level 1) CS2002 - Compiler Warning (level 1) CS2023 @@ -115,6 +133,14 @@ Specify a file to log all compiler and analyzer diagnostics. The **ErrorLog** option causes the compiler to output a [Static Analysis Results Interchange Format (SARIF) log](https://github.com/microsoft/sarif-tutorials/blob/main/docs/1-Introduction.md#:~:text=What%20is%20SARIF%3F,for%20use%20by%20simpler%20tools). SARIF logs are typically read by tools that analyze the results from compiler and analyzer diagnostics. +You can specify the SARIF format using the `version` argument to the `ErrorLog` element: + +```XML +logVersion21.json,version=2.1 +``` + +The separator can be either a comma (`,`) or a semicolon (`;`). Valid values are for version are: "1", "2", and "2.1". The default is "1". "2" and "2.1" both mean SARIF version 2.1.0. + ## ReportAnalyzer Report additional analyzer information, such as execution time. @@ -124,3 +150,6 @@ Report additional analyzer information, such as execution time. ``` The **ReportAnalyzer** option causes the compiler to emit extra MSBuild log information that details the performance characteristics of analyzers in the build. It's typically used by analyzer authors as part of validating the analyzer. + +> [!IMPORTANT] +> The extra log information generated by this flag is only generated when the `-verbosity:detailed` command line option is used. See the [swtiches](/visualstudio/msbuild/msbuild-command-line-reference#switches) article in the MSBuild documentation for more information. diff --git a/docs/csharp/whats-new/csharp-10.md b/docs/csharp/whats-new/csharp-10.md index a38832863b5ae..ce18f38c594cd 100644 --- a/docs/csharp/whats-new/csharp-10.md +++ b/docs/csharp/whats-new/csharp-10.md @@ -21,6 +21,7 @@ C# 10 adds the following features and enhancements to the C# language: - [Allow `AsyncMethodBuilder` attribute on methods](#allow-asyncmethodbuilder-attribute-on-methods) - [CallerArgumentExpression attribute](#callerargumentexpression-attribute-diagnostics) - [Enhanced `#line` pragma](#enhanced-line-pragma) +- [Warning wave 6](../language-reference/compiler-messages/warning-waves.md#cs8826---partial-method-declarations-have-signature-differences) C# 10 is supported on **.NET 6**. For more information, see [C# language versioning](../language-reference/configure-language-version.md). diff --git a/docs/csharp/whats-new/csharp-11.md b/docs/csharp/whats-new/csharp-11.md index bdbb7aa7e3a6e..62b95c475a4f5 100644 --- a/docs/csharp/whats-new/csharp-11.md +++ b/docs/csharp/whats-new/csharp-11.md @@ -1,7 +1,7 @@ --- title: What's new in C# 11 - C# Guide description: Get an overview of the new features coming in C# 11. -ms.date: 04/15/2022 +ms.date: 05/11/2022 --- # What's new in C# 11 @@ -18,6 +18,7 @@ The following features are available in the 6.0.200 version of the .NET SDK. The - [Newlines in string interpolation expressions](#newlines-in-string-interpolations). - [Improved method group conversion to delegate](#improved-method-group-conversion-to-delegate) - [Raw string literals](#raw-string-literals). +- [Warning wave 7](../language-reference/compiler-messages/warning-waves.md#cs8981---the-type-name-only-contains-lower-cased-ascii-characters) You can download the latest .NET 6 SDK from the [.NET downloads page](https://dotnet.microsoft.com/download). You can also download [Visual Studio 2022](https://visualstudio.microsoft.com/vs/), which includes the .NET 6 SDK. You can also try all these features with the preview release of the .NET 7 SDK, which can be downloaded from the [all .NET downloads](https://dotnet.microsoft.com/download/dotnet) page. diff --git a/docs/csharp/whats-new/csharp-9.md b/docs/csharp/whats-new/csharp-9.md index c1bdc17d3ffe3..9a8a7cfd1e5d1 100644 --- a/docs/csharp/whats-new/csharp-9.md +++ b/docs/csharp/whats-new/csharp-9.md @@ -26,6 +26,7 @@ C# 9.0 adds the following features and enhancements to the C# language: - [Support for code generators](#support-for-code-generators) - [Module initializers](~/_csharplang/proposals/csharp-9.0/module-initializers.md) - [New features for partial methods](~/_csharplang/proposals/csharp-9.0/extending-partial-methods.md) +- [Warning wave 5](../language-reference/compiler-messages/warning-waves.md#cs7023---a-static-type-is-used-in-an-is-or-as-expression) C# 9.0 is supported on **.NET 5**. For more information, see [C# language versioning](../language-reference/configure-language-version.md).