From c64e4c7382c98132631edabcef439488e99152ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:02:40 +0000 Subject: [PATCH 01/16] Add CA2266 analyzer docs --- docs/fundamentals/code-analysis/overview.md | 1 + .../code-analysis/quality-rules/ca2266.md | 96 +++++++++++++++++++ .../code-analysis/quality-rules/index.md | 1 + .../quality-rules/usage-warnings.md | 3 +- docs/navigate/tools-diagnostics/toc.yml | 2 + 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 docs/fundamentals/code-analysis/quality-rules/ca2266.md diff --git a/docs/fundamentals/code-analysis/overview.md b/docs/fundamentals/code-analysis/overview.md index 5867a1ac35513..406631417329e 100644 --- a/docs/fundamentals/code-analysis/overview.md +++ b/docs/fundamentals/code-analysis/overview.md @@ -58,6 +58,7 @@ The following rules are enabled, by default, as errors or warnings in .NET 10. A | [CA2261](quality-rules/ca2261.md) | Usage | Warning | .NET 8 | Do not use `ConfigureAwaitOptions.SuppressThrowing` with `Task` | | [CA2264](quality-rules/ca2264.md) | Usage | Warning | .NET 9 | Do not pass a non-nullable value to `ArgumentNullException.ThrowIfNull` | | [CA2265](quality-rules/ca2265.md) | Usage | Warning | .NET 9 | Do not compare `Span` to `null` or `default` | +| [CA2266](quality-rules/ca2266.md) | Usage | Warning | .NET 10 | File-based program entry point should start with `#!` | # [.NET 9](#tab/net-9) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md new file mode 100644 index 0000000000000..e4e39695fd9aa --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -0,0 +1,96 @@ +--- +title: "CA2266: File-based program entry point should start with '#!'" +description: "Learn about code analysis rule CA2266 - File-based program entry point should start with '#!'" +ms.date: 05/21/2026 +f1_keywords: + - CA2266 +helpviewer_keywords: + - CA2266 +dev_langs: + - CSharp +--- + +# CA2266: File-based program entry point should start with `#!` + +| Property | Value | +|-------------------------------------|----------------------------------------------------| +| **Rule ID** | CA2266 | +| **Title** | File-based program entry point should start with `#!` | +| **Category** | [Usage](usage-warnings.md) | +| **Fix is breaking or non-breaking** | Non-breaking | +| **Enabled by default in .NET 10** | As warning | +| **Applicable languages** | C# | + +## Cause + +The entry point file in a multi-file file-based program doesn't start with a shebang (`#!`) line. + +## Rule description + +When a file-based program consists of multiple files, the entry point file should start with a shebang (`#!`) line to clearly distinguish it from files brought in with `#:include`. This helps tools identify the entry point correctly and improves direct shell execution support. + +## How to fix violations + +Add a shebang line to the beginning of the entry point file, for example, `#!/usr/bin/env dotnet`. + +## Example + +The following code snippet shows a violation of CA2266. + +In `app.cs`: + +```csharp +#:include "helpers.cs" + +Console.WriteLine(GetMessage()); +``` + +In `helpers.cs`: + +```csharp +string GetMessage() => "Hello"; +``` + +The following code snippet fixes the violation. + +In `app.cs`: + +```csharp +#!/usr/bin/env dotnet +#:include "helpers.cs" + +Console.WriteLine(GetMessage()); +``` + +In `helpers.cs`: + +```csharp +string GetMessage() => "Hello"; +``` + +## When to suppress warnings + +It's safe to suppress this warning if you intentionally omit the shebang line and you've confirmed that your tooling can still identify the entry point correctly. + +## Suppress a warning + +If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule. + +```csharp +#pragma warning disable CA2266 +// The code that's violating the rule is on this line. +#pragma warning restore CA2266 +``` + +To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md). + +```ini +[*.cs] +dotnet_diagnostic.CA2266.severity = none +``` + +For more information, see [How to suppress code analysis warnings](../suppress-warnings.md). + +## See also + +- [File-based apps](../../../csharp/tour-of-csharp/overview.md#file-based-apps) diff --git a/docs/fundamentals/code-analysis/quality-rules/index.md b/docs/fundamentals/code-analysis/quality-rules/index.md index e88df83dcf8d9..3fae2300fdc03 100644 --- a/docs/fundamentals/code-analysis/quality-rules/index.md +++ b/docs/fundamentals/code-analysis/quality-rules/index.md @@ -249,6 +249,7 @@ The following table lists code quality analysis rules. > | [CA2263: Prefer generic overload when type is known](ca2263.md) | Using a generic overload is preferable to passing a argument when the type is known, because they promote cleaner and more type-safe code with improved compile-time checks. | > | [CA2264: Do not pass a non-nullable value to `ArgumentNullException.ThrowIfNull`](ca2264.md) | `ArgumentNullException.ThrowIfNull` throws when the passed argument is `null`. Certain constructs like non-nullable structs, and `nameof()` and `new` expressions are known to never be null, so `ArgumentNullException.ThrowIfNull` will never throw. | > | [CA2265: Do not compare `Span` to `null` or `default`](ca2265.md) | Comparing a span to `null` or `default` might not do what you intended. `default` and the `null` literal are implicitly converted to `Span.Empty`. | +> | [CA2266: File-based program entry point should start with `#!`](ca2266.md) | When a file-based program consists of multiple files, the entry point file should start with a shebang (`#!`) line to clearly distinguish it from other included files. | > | [CA2300: Do not use insecure deserializer BinaryFormatter](ca2300.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | > | [CA2301: Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder](ca2301.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | > | [CA2302: Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize](ca2302.md) | Insecure deserializers are vulnerable when deserializing untrusted data. An attacker could modify the serialized data to include unexpected types to inject objects with malicious side effects. | diff --git a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md index 39ab1b3132689..dd60df7442bf5 100644 --- a/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/usage-warnings.md @@ -62,6 +62,7 @@ Usage rules support proper usage of .NET. | [CA2260: Implement generic math interfaces correctly](ca2260.md) | Generic math interfaces require the derived type itself to be used for the self-recurring type parameter. | | [CA2261: Do not use `ConfigureAwaitOptions.SuppressThrowing` with `Task`](ca2261.md) | The `ConfigureAwaitOptions.SuppressThrowing` option isn't supported by the generic `Task`, since that might lead to returning an invalid `TResult`. | | [CA2262: Set `MaxResponseHeadersLength` properly](ca2262.md) | Make sure the `MaxResponseHeadersLength` value is provided correctly. This value is measured in kilobytes. | +| [CA2263: Prefer generic overload when type is known](ca2263.md) | Using a generic overload is preferable to passing a argument when the type is known, because they promote cleaner and more type-safe code with improved compile-time checks. | | [CA2264: Do not pass a non-nullable value to 'ArgumentNullException.ThrowIfNull'](ca2264.md) | 'ArgumentNullException.ThrowIfNull' throws when the passed argument is 'null'. Certain constructs like non-nullable structs, and 'nameof()' and 'new' expressions are known to never be null, so 'ArgumentNullException.ThrowIfNull' will never throw. | | [CA2265: Do not compare `Span` to `null` or `default`](ca2265.md) | Comparing a span to `null` or `default` might not do what you intended. `default` and the `null` literal are implicitly converted to `Span.Empty`. | -| [CA2263: Prefer generic overload when type is known](ca2263.md) | Using a generic overload is preferable to passing a argument when the type is known, because they promote cleaner and more type-safe code with improved compile-time checks. | +| [CA2266: File-based program entry point should start with `#!`](ca2266.md) | When a file-based program consists of multiple files, the entry point file should start with a shebang (`#!`) line to clearly distinguish it from other included files. | diff --git a/docs/navigate/tools-diagnostics/toc.yml b/docs/navigate/tools-diagnostics/toc.yml index 5cb6258113bc3..cdb2ae2d8caa0 100644 --- a/docs/navigate/tools-diagnostics/toc.yml +++ b/docs/navigate/tools-diagnostics/toc.yml @@ -3674,6 +3674,8 @@ items: href: ../../fundamentals/code-analysis/quality-rules/ca2264.md - name: CA2265 href: ../../fundamentals/code-analysis/quality-rules/ca2265.md + - name: CA2266 + href: ../../fundamentals/code-analysis/quality-rules/ca2266.md - name: Code style rules items: - name: Overview From 1bc3493b1a0b7fc7b74b3e01d5605c2b1e7299b6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:03:32 +0000 Subject: [PATCH 02/16] Link CA2266 from .NET 10 SDK notes --- docs/core/whats-new/dotnet-10/sdk.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/core/whats-new/dotnet-10/sdk.md b/docs/core/whats-new/dotnet-10/sdk.md index 03945bd68a88c..fc03de1268a1d 100644 --- a/docs/core/whats-new/dotnet-10/sdk.md +++ b/docs/core/whats-new/dotnet-10/sdk.md @@ -174,6 +174,8 @@ File-based apps also include enhanced features: - **Runtime path access**: App file and directory paths are available at runtime via `System.AppContext.GetData`. - **Enhanced shebang support**: Direct shell execution with improved shebang handling, including support for extensionless files. +For multi-file file-based apps that use `#:include`, analyzer [CA2266](../../../fundamentals/code-analysis/quality-rules/ca2266.md) warns when the entry-point file doesn't start with a shebang line. + #### Project referencing example ```csharp From ae418f62702b9c624a1554888cf4eaae2e8b8945 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:04:41 +0000 Subject: [PATCH 03/16] Address CA2266 doc review feedback --- docs/core/whats-new/dotnet-10/sdk.md | 2 +- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/core/whats-new/dotnet-10/sdk.md b/docs/core/whats-new/dotnet-10/sdk.md index fc03de1268a1d..6b7100922433e 100644 --- a/docs/core/whats-new/dotnet-10/sdk.md +++ b/docs/core/whats-new/dotnet-10/sdk.md @@ -174,7 +174,7 @@ File-based apps also include enhanced features: - **Runtime path access**: App file and directory paths are available at runtime via `System.AppContext.GetData`. - **Enhanced shebang support**: Direct shell execution with improved shebang handling, including support for extensionless files. -For multi-file file-based apps that use `#:include`, analyzer [CA2266](../../../fundamentals/code-analysis/quality-rules/ca2266.md) warns when the entry-point file doesn't start with a shebang line. +To help you identify the entry point in multi-file file-based apps, analyzer [CA2266](../../../fundamentals/code-analysis/quality-rules/ca2266.md) warns when the entry-point file doesn't start with a shebang line. #### Project referencing example diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index e4e39695fd9aa..6a509a3b81241 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -27,7 +27,7 @@ The entry point file in a multi-file file-based program doesn't start with a she ## Rule description -When a file-based program consists of multiple files, the entry point file should start with a shebang (`#!`) line to clearly distinguish it from files brought in with `#:include`. This helps tools identify the entry point correctly and improves direct shell execution support. +When you create a multi-file file-based program, start the entry point file with a shebang (`#!`) line to clearly distinguish it from files brought in with `#:include`. This helps tools identify the entry point correctly and improves direct shell execution support. ## How to fix violations @@ -93,4 +93,4 @@ For more information, see [How to suppress code analysis warnings](../suppress-w ## See also -- [File-based apps](../../../csharp/tour-of-csharp/overview.md#file-based-apps) +[File-based apps](../../../csharp/tour-of-csharp/overview.md#file-based-apps) From 422ad3dae8cd6af3474b9fb01ebf91c42e90ba99 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:05:54 +0000 Subject: [PATCH 04/16] Polish CA2266 rule wording --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index 6a509a3b81241..d3c44965dab18 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -27,7 +27,7 @@ The entry point file in a multi-file file-based program doesn't start with a she ## Rule description -When you create a multi-file file-based program, start the entry point file with a shebang (`#!`) line to clearly distinguish it from files brought in with `#:include`. This helps tools identify the entry point correctly and improves direct shell execution support. +To create a multi-file file-based program, start the entry point file with a shebang (`#!`) line to clearly distinguish it from files brought in with `#:include`. This helps tools identify the entry point correctly, and improves direct shell execution support. ## How to fix violations @@ -70,7 +70,7 @@ string GetMessage() => "Hello"; ## When to suppress warnings -It's safe to suppress this warning if you intentionally omit the shebang line and you've confirmed that your tooling can still identify the entry point correctly. +It is safe to suppress this warning if you intentionally omit the shebang line and have confirmed that your tooling can still identify the entry point correctly. ## Suppress a warning From d5d9f021e39fcbeca88f7d0604b6c16ba75f8374 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:06:58 +0000 Subject: [PATCH 05/16] Refine CA2266 guidance wording --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index d3c44965dab18..4fe471c912c94 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -27,7 +27,7 @@ The entry point file in a multi-file file-based program doesn't start with a she ## Rule description -To create a multi-file file-based program, start the entry point file with a shebang (`#!`) line to clearly distinguish it from files brought in with `#:include`. This helps tools identify the entry point correctly, and improves direct shell execution support. +For correct tool identification and direct shell execution support, start the entry point file with a shebang (`#!`) line to clearly distinguish it from files brought in with `#:include`. ## How to fix violations @@ -70,7 +70,7 @@ string GetMessage() => "Hello"; ## When to suppress warnings -It is safe to suppress this warning if you intentionally omit the shebang line and have confirmed that your tooling can still identify the entry point correctly. +If you intentionally omit the shebang line and have confirmed that your tooling can still identify the entry point correctly, it is safe to suppress this warning. ## Suppress a warning From 47b4d8454b9c6493fcb6109c1abf6c4fc52cf1a7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:08:21 +0000 Subject: [PATCH 06/16] Adjust CA2266 related link --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index 4fe471c912c94..15f7b3e0907c3 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -93,4 +93,4 @@ For more information, see [How to suppress code analysis warnings](../suppress-w ## See also -[File-based apps](../../../csharp/tour-of-csharp/overview.md#file-based-apps) +[Build file-based apps](../../../csharp/fundamentals/tutorials/file-based-programs.md) From 49381ed76e018ba64ee8f7dbcd2ce28ffacfdf92 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:09:15 +0000 Subject: [PATCH 07/16] Tighten CA2266 cause wording --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index 15f7b3e0907c3..fddb262c341d1 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -23,7 +23,7 @@ dev_langs: ## Cause -The entry point file in a multi-file file-based program doesn't start with a shebang (`#!`) line. +Your entry point file in a multi-file file-based program doesn't start with a shebang (`#!`) line. ## Rule description From 0b8bea3d63c81eac71755c42a23b92d3f04792aa Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Thu, 21 May 2026 16:41:27 +0200 Subject: [PATCH 08/16] Add ai-usage key Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index fddb262c341d1..20b601b15972a 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -8,6 +8,7 @@ helpviewer_keywords: - CA2266 dev_langs: - CSharp +ai-usage: ai-assisted --- # CA2266: File-based program entry point should start with `#!` From cb33788d2b0f13a24506be25acee4debdfdaef47 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Thu, 21 May 2026 16:44:07 +0200 Subject: [PATCH 09/16] Remove from what's new --- docs/core/whats-new/dotnet-10/sdk.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/core/whats-new/dotnet-10/sdk.md b/docs/core/whats-new/dotnet-10/sdk.md index 6b7100922433e..03945bd68a88c 100644 --- a/docs/core/whats-new/dotnet-10/sdk.md +++ b/docs/core/whats-new/dotnet-10/sdk.md @@ -174,8 +174,6 @@ File-based apps also include enhanced features: - **Runtime path access**: App file and directory paths are available at runtime via `System.AppContext.GetData`. - **Enhanced shebang support**: Direct shell execution with improved shebang handling, including support for extensionless files. -To help you identify the entry point in multi-file file-based apps, analyzer [CA2266](../../../fundamentals/code-analysis/quality-rules/ca2266.md) warns when the entry-point file doesn't start with a shebang line. - #### Project referencing example ```csharp From 7a6e07beb83d1e665e70170eee74aa65ce52e17d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:57:25 +0000 Subject: [PATCH 10/16] Refine CA2266 suppression guidance --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index 20b601b15972a..0b2300688735e 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -75,12 +75,10 @@ If you intentionally omit the shebang line and have confirmed that your tooling ## Suppress a warning -If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule. +If you just want to suppress a single violation in a file-based app, add a `#:property` directive to the entry point file. ```csharp -#pragma warning disable CA2266 -// The code that's violating the rule is on this line. -#pragma warning restore CA2266 +#:property NoWarn=CA2266 ``` To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md). @@ -94,4 +92,4 @@ For more information, see [How to suppress code analysis warnings](../suppress-w ## See also -[Build file-based apps](../../../csharp/fundamentals/tutorials/file-based-programs.md) +[File-based apps](../../../core/sdk/file-based-apps.md#shell-execution) From 7cba11674af7d57cdfa2a10416f531e02b897294 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:59:07 +0000 Subject: [PATCH 11/16] Clarify CA2266 suppression scope --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index 0b2300688735e..107dcdb5c11db 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -75,7 +75,7 @@ If you intentionally omit the shebang line and have confirmed that your tooling ## Suppress a warning -If you just want to suppress a single violation in a file-based app, add a `#:property` directive to the entry point file. +If you just want to suppress a single violation in a file-based app, add a `#:property` directive to the entry point file. This syntax is specific to file-based apps; use `#pragma warning` directives for traditional project-based source files. ```csharp #:property NoWarn=CA2266 From 1303c3c4148f70b275535461e480cc69b07dcf03 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 14:59:55 +0000 Subject: [PATCH 12/16] Polish CA2266 suppression wording --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index 107dcdb5c11db..99d03dd44c42e 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -75,7 +75,7 @@ If you intentionally omit the shebang line and have confirmed that your tooling ## Suppress a warning -If you just want to suppress a single violation in a file-based app, add a `#:property` directive to the entry point file. This syntax is specific to file-based apps; use `#pragma warning` directives for traditional project-based source files. +To suppress a single violation in a file-based app, add a `#:property` directive to the entry point file. For traditional project-based source files, use `#pragma warning` directives instead. ```csharp #:property NoWarn=CA2266 From ed1accf5e594874c2471997c392590e6e525ae97 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 15:00:45 +0000 Subject: [PATCH 13/16] Refine CA2266 suppression sentence --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index 99d03dd44c42e..120e26da66786 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -75,7 +75,7 @@ If you intentionally omit the shebang line and have confirmed that your tooling ## Suppress a warning -To suppress a single violation in a file-based app, add a `#:property` directive to the entry point file. For traditional project-based source files, use `#pragma warning` directives instead. +For file-based apps, suppress a single violation by adding a `#:property` directive to the entry point file. For traditional project-based source files, use `#pragma warning` directives instead. ```csharp #:property NoWarn=CA2266 From a59e17a9a622323f31e46afd789e1477b6673d42 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 21 May 2026 15:01:27 +0000 Subject: [PATCH 14/16] Adjust CA2266 suppression phrasing --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index 120e26da66786..0251067e9c117 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -75,7 +75,7 @@ If you intentionally omit the shebang line and have confirmed that your tooling ## Suppress a warning -For file-based apps, suppress a single violation by adding a `#:property` directive to the entry point file. For traditional project-based source files, use `#pragma warning` directives instead. +For file-based apps, suppress a single violation by adding a `#:property` directive to the entry point file. For traditional project-based source files, add `#pragma warning` directives instead. ```csharp #:property NoWarn=CA2266 From a30c06e8ef78f9588df85a3c3c9868a616172b1b Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 22 May 2026 10:56:56 +0200 Subject: [PATCH 15/16] Remove invalid suggestion --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index 0251067e9c117..ad8af58dcc0ba 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -75,7 +75,7 @@ If you intentionally omit the shebang line and have confirmed that your tooling ## Suppress a warning -For file-based apps, suppress a single violation by adding a `#:property` directive to the entry point file. For traditional project-based source files, add `#pragma warning` directives instead. +For file-based apps, suppress a single violation by adding a `#:property` directive to the entry point file. ```csharp #:property NoWarn=CA2266 From 4ff142f763ae2989db412ce8b3fdc8e660a61dc4 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 22 May 2026 11:07:18 +0200 Subject: [PATCH 16/16] Improve NoWarn --- docs/fundamentals/code-analysis/quality-rules/ca2266.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2266.md b/docs/fundamentals/code-analysis/quality-rules/ca2266.md index ad8af58dcc0ba..510bee500c6a5 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2266.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2266.md @@ -78,7 +78,7 @@ If you intentionally omit the shebang line and have confirmed that your tooling For file-based apps, suppress a single violation by adding a `#:property` directive to the entry point file. ```csharp -#:property NoWarn=CA2266 +#:property NoWarn=$(NoWarn);CA2266 ``` To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md).