# code-quality

Adopt this skill: https://proskills.md/skills/other/microsoft-winappcli-github-skills-code-quality

Page: https://proskills.md/skills/other/microsoft-winappcli-github-skills-code-quality
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: .github/skills/code-quality/SKILL.md
size: 8164
upstream: https://github.com/microsoft/winappcli/blob/main/.github/skills/code-quality/SKILL.md

```text
---
name: code-quality
description: Statically check changed C# against the same deterministic rules github-code-quality[bot] runs on pull requests, so a contributor can fix likely findings before opening the PR and keep the bot's inline comments to a minimum. Activate when a contributor asks to "check code quality", "run code quality on my changes", "will the code quality bot complain", "pre-check before I open the PR", "code quality check", or similar. Scoped to C#. Reads the diff and compares it against the enumerated csharp-code-quality rule set below — no CodeQL download or build required. This is a fast approximation of a dataflow engine, not a reproduction; report accordingly. Does NOT apply fixes unless explicitly asked.
infer: true
---

You are the **local code-quality pre-check** for `microsoft/winappcli`. On pull
requests, `github-code-quality[bot]` runs the deterministic CodeQL
**`csharp-code-quality`** suite and posts each hit as an inline comment. This
skill reads the contributor's C# diff and flags lines that are likely to trip
those same rules, so they can be cleared before pushing.

Scope is **C# only** — the language the bot rule-checks in this repo.

**Be honest about what this is.** The bot runs a deterministic dataflow/type
engine; you are pattern-matching a diff by reading it. You will reliably catch the
syntactic rules and miss or over-flag the analysis-heavy ones (marked **†**
below — null-flow, disposal escape analysis, "value never used", LINQ shape
detection). Treat **†** findings as *lower confidence*, and never claim a clean
result guarantees zero bot comments. It does not — it means nothing *obvious* is
left. This also does not cover the bot's separate AI-powered pass, or C/C++.

Do **not** activate for a single "is this line okay" question — that is a direct
question, not a diff-wide pre-check.

## 1. Scope to the changed C# code

First find the merge base, so committed *and* still-uncommitted work both count —
call it `<base>`: `git merge-base origin/main HEAD`.

- **Tracked changes** (branch commits plus any staged/unstaged edits):
  `git --no-pager diff --name-only <base>` — diffing the working tree against the
  merge base, so a later edit to an already-committed file is still seen.
- **Untracked new files:** `git ls-files --others --exclude-standard -- "src/*.cs"`
  — `git diff` cannot emit hunks for these; read them directly with `view`.

Keep only `*.cs` under `src\`, and drop files matching the repo's CodeQL exclusion
`**/*Tests/*.cs` — a `.cs` file **directly inside** a directory whose name ends in
`Tests` (e.g. `src\WinApp.Cli.Tests\Foo.cs`). Mirror that glob exactly: a file
nested deeper, such as `src\...\WinApp.Cli.Tests\TestApps\App.xaml.cs`, does **not**
match it, so the bot may scan it — keep those in scope. If nothing survives, say
so and stop.

Then read the changed lines. For a tracked file:
`git --no-pager diff --unified=0 <base> -- <file>`; for an untracked file the whole
file is added, so `view` it. Either way `view` each changed region for context.
**Only flag code inside the changed hunks** — the bot comments on changed lines,
and pre-existing debt elsewhere is not this PR's problem.

## 2. Check the diff against the rule set

For every changed hunk, walk the rule tables below and flag each line that
matches. For a match, record the `cs/...` id, the exact `file:line`, the offending
snippet, and the smallest fix. Prefer precision over volume: if you cannot point
at the specific line and say what the bot would say, drop it. Apply extra
skepticism to **†** rules — only raise one when the trigger is visible in the diff
(e.g. a `new HttpRequestMessage(...)` with no `using` and no `return`/field
assignment), not on a hunch.

### Exception handling
| Rule | Flags → do instead |
|---|---|
| `cs/catch-of-all-exceptions` | `catch (Exception)` (or bare `catch`) → catch the specific type you can handle |
| `cs/catch-nullreferenceexception` | catching `NullReferenceException` → fix the deref; don't catch it |
| `cs/empty-catch-block` | `catch {}` that swallows → handle, log, or let it propagate |
| `cs/rethrown-exception-variable` | `throw ex;` (resets stack) → `throw;` |

### Null & dereference — **†**
| Rule | Flags → do instead |
|---|---|
| `cs/dereferenced-value-may-be-null` **†** | using a value that a prior branch/API can leave null → null-check or `?.` |
| `cs/dereferenced-value-is-always-null` **†** | dereffing a value provably always null → remove/repair |
| `cs/null-argument-to-equals` | `x.Equals(null)` → `x is null` |

### Disposal & resources
| Rule | Flags → do instead |
|---|---|
| `cs/local-not-disposed` **†** | a local `IDisposable` you own, never disposed → `using` |
| `cs/missed-using-statement` **†** | `Dispose()` in a `finally` you could express as `using` → `using` |

### Equality & hashing
| Rule | Flags → do instead |
|---|---|
| `cs/gethashcode-is-not-defined` | overriding `Equals` without `GetHashCode` → override both |
| `cs/useless-gethashcode-call` | `GetHashCode()` on a small integral type (e.g. `int`, `enum`) — it just returns the value → drop the redundant call |
| `cs/equals-on-arrays` | `array.Equals(other)` (reference eq) → `SequenceEqual` |
| `cs/equals-on-unrelated-types` | `Equals` across incomparable types → compare compatible types |
| `cs/unchecked-cast-in-equals` | unchecked cast of the arg in an `Equals` override → `is`/`as` guard |
| `cs/recursive-equals-call` | `Equals` calling itself unboundedly → fix the recursion |
| `cs/reference-equality-on-valuetypes` | `ReferenceEquals` on value types (always false) → `==`/`Equals` |
| `cs/equality-on-floats` | `==` on `double`/`float` → compare with a tolerance |
| `cs/comparison-of-identical-expressions` | a comparison operator with identical operands (`x == x`, `a < a`) → remove or fix the typo |

### Dead & useless code
| Rule | Flags → do instead |
|---|---|
| `cs/empty-block` | empty `if`/loop body → remove or fill |
| `cs/useless-if-statement` | `if` whose branches do the same thing → collapse |
| `cs/constant-condition` **†** | condition provably always true/false → remove the dead path |
| `cs/simplifiable-boolean-expression` | `x ? true : false`, `!(a == b)` → simplify |
| `cs/missed-ternary-operator` | `if/else` that only assigns one variable → ternary |
| `cs/nested-if-statements` | `if (a) { if (b) … }` with no else → `if (a && b)` |
| `cs/useless-tostring-call` | `.ToString()` on a `string` / in interpolation → drop it |
| `cs/call-to-object-tostring` | default `object.ToString()` (type name) → override or format explicitly |
| `cs/self-assignment` | `x = x;` → remove (or fix the intended target) |
| `cs/unused-label` | a `label:` never targeted → remove |
| `cs/unused-property-value` **†** | setter that ignores `value` → use it |
| `cs/empty-collection` **†** | a collection created empty and then read/used but never given any elements → add elements or drop the reads |
| `cs/unused-collection` **†** | a collection filled but never read → remove or use |

### LINQ opportunities — **†**
| Rule | Flags → do instead |
|---|---|
| `cs/linq/missed-where` **†** | `foreach` with a filtering `if` → `.Where(...)` |
| `cs/linq/missed-select` **†** | `foreach` that only projects → `.Select(...)` |
| `cs/linq/missed-all` **†** | loop checking a condition holds for all → `.All(...)` |
| `cs/linq/missed-cast` **†** | loop casting every element → `.Cast<T>()` |
| `cs/linq/missed-oftype` **†** | loop filtering by type → `.OfType<T>()` |
| `cs/linq/useless-select` | `.Select(x => x)` → drop it |

### Collections & indexing
| Rule | Flags → do instead |
|---|---|
| `cs/inefficient-containskey` | `ContainsKey` then indexer → `TryGetValue` |
| `cs/test-for-negative-container-size` | `Count < 0` / `Length < 0` (never true) → fix the check |
| `cs/index-out-of-bounds` **†** | off-by-one vs `Length`/`Count` → use `< Length` |
| `cs/nested-loops-with-same-variable` | nested `for`/`foreach` that reuse the same counter (inner loop als
```

## File: README.md
upstream: https://github.com/microsoft/winappcli/blob/main/README.md

```text
# WinApp CLI

> [!IMPORTANT]
> :warning: **Status: Public Preview** — The Windows App Development CLI (WinApp CLI) is experimental and in active development. We'd love your feedback! Share your thoughts by creating an [issue](https://github.com/microsoft/WinAppCli/issues).

> [!NOTE]
> The **`main` branch** contains work that is in **active development**. Documentation, features, and behavior here may differ from what is publicly released. For the latest stable version, see the [latest release](https://github.com/microsoft/WinAppCli/releases/latest). To try the newest in-progress build, see [Install from latest build](#install-from-latest-build-main-branch) below.

<p align="center">
    <picture>
      <img  src="./docs/images/winapp-terminal.png">
    </picture>
</p>
<br/>
<p align="center">
  <img src="https://img.shields.io/winget/v/Microsoft.WinAppCli?style=for-the-badge&logo=windows&color=357EC7" alt="WinGet">
  <a href="https://www.npmjs.com/package/@microsoft/winappcli">
    <img src="https://img.shields.io/npm/v/%40microsoft%2Fwinappcli?style=for-the-badge&logo=npm" alt="NPM">
  </a>
  <a href="https://www.nuget.org/packages/Microsoft.Windows.SDK.BuildTools.WinApp">
    <img src="https://img.shields.io/nuget/v/Microsoft.Windows.SDK.BuildTools.WinApp?style=for-the-badge&logo=nuget&label=NuGet&color=004880" alt="NuGet">
  </a>
  <a href="https://github.com/microsoft/WinAppCli/releases/latest">
    <img src="https://img.shields.io/github/v/release/microsoft/WinAppCli?style=for-the-badge&logo=github&label=Latest%20Release&color=8ab4f8" alt="Latest Release">
  </a>
  <br />
  <a href="https://github.com/microsoft/WinAppCli/issues">
    <img src="https://img.shields.io/github/issues/microsoft/WinAppCli?style=for-the-badge&logo=github&color=81c995" alt="Issues">
  </a>
  <a href="https://github.com/microsoft/WinAppCli/blob/main/LICENSE">
    <img alt="GitHub License" src="https://img.shields.io/github/license/microsoft/winappcli?style=for-the-badge">
  </a>
  <br />
  <a href="https://github.com/microsoft/WinAppCli/actions/workflows/build-package.yml?query=branch%3Amain">
    <img src="https://img.shields.io/github/actions/workflow/status/microsoft/WinAppCli/build-package.yml?branch=main&style=for-the-badge&logo=githubactions&logoColor=white&label=Build%20(main)" alt="Build Status">
  </a>
</p>

<h3 align="center">
  <a href="#-why-package-identity">Why?</a>
  <span> • </span>
  <a href="#%EF%B8%8F-get-started">Get Started</a>
  <span> • </span>
  <a href="#-installation">Installation</a>
  <span> • </span>
  <a href="#-usage">Usage</a>
  <span> • </span>
  <a href="https://learn.microsoft.com/windows/apps/dev-tools/winapp-cli/">Docs</a>
  <span> • </span>
  <a href="#-feedback-and-support">Feedback</a>
</h3>
<br/>

The Windows App Development CLI (WinApp CLI) is a single command-line interface for creating, running, debugging, testing, and packaging Windows apps. It manages Windows SDKs, app identity, manifests, certificates, and build tools for WinUI and any other app framework.
<br/><br/>
Whether you're building with WinUI, .NET/Win32, CMake, Electron, or Rust, this CLI gives you access to:

- **WinUI from the terminal** - Create apps from official templates with `winapp new` and launch them with `winapp run`
- **Modern Windows APIs** - [Windows App SDK](https://learn.microsoft.com/windows/apps/windows-app-sdk/) and Windows SDK with automatic setup and code generation
- **Package Identity** - Debug and test by adding package identity without full packaging in a snap
- **MSIX Packaging** - App packaging with signing and Store readiness
- **UI automation and agent tooling** - Inspect and drive running apps with `winapp ui`, and ground AI coding agents with `find-ui` and `find-api`
- **Developer Tools** - Manifests, certificates, assets, and build integration

Full documentation is published on Microsoft Learn: **[Windows App Development CLI](https://learn.microsoft.com/windows/apps/dev-tools/winapp-cli/)**.

Perfect for:

- **WinUI developers** who want to create, run, test, and package apps from the terminal, VS Code, or an AI coding agent
- **Cross-platform developers using frameworks like Qt or Electron** wanting native Windows features or targeting Windows
- **Developers who love their current tools** and want to build Windows apps from VS Code, or any other editor
- **Developers crafting CI/CD pipelines** to automate building apps for Windows

## 🤔 Why?

Many Windows APIs require your app to have package identity, enabling you to leverage some of the OS components Windows offers, that you wouldn't otherwise have access to. With identity, your app gains access to user-first features like notifications, OS integration, and on-device AI.

Our goal is to support developers wherever they are, with the tools and frameworks they already use. Based on feedback from developers shipping cross-platform apps on Windows, we built this CLI to streamline integrating with the Windows developer platform - handling SDK setup, header generation, manifests, certificates, and packaging in just a few commands:

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="./docs/images/before-after-winapp-dark.png">
    <source media="(prefers-color-scheme: light)" srcset="./docs/images/before-after-winapp.png">
    <img src="./docs/images/before-after-winapp.png" alt="Before: 12 manual steps to access Windows APIs. After: 4 WinApp CLI commands (init, create-addon, add-electron-debug-identity, pack)">
  </picture>
</p>
<p align="center"><i>Without WinApp CLI, setting up a project involves 12 manual steps—downloading SDKs, generating headers, creating manifests, and more. With the CLI, it's just 4 commands.</i></p>

**A few examples of what package identity and MSIX packaging unlock:**

- [Interactive native notifications](https://learn.microsoft.com/windows/apps/develop/notifications/app-notifications/app-notifications-quickstart?tabs=cs) and notification management
- [Integration with Windows Explorer, Taskbar, Share sheet](https://learn.microsoft.com/windows/apps/develop/windows-integration/integrate-sharesheet-packaged), and other shell surfaces
- [Protocol handlers](https://learn.microsoft.com/windows/apps/desktop/modernize/desktop-to-uwp-extensions#start-your-application-in-different-ways) (`yourapp://` URIs)
- [Web-to-app linking](https://learn.microsoft.com/windows/apps/develop/launch/web-to-app-linking) (`yoursite.com` opens your app)
- [On-device AI](https://learn.microsoft.com/windows/ai/apis/) (Local LLM, Text and Image AI APIs)
- [Custom CLI commands via AppExecutionAlias](https://learn.microsoft.com/windows/apps/desktop/modernize/desktop-to-uwp-extensions#start-your-application-in-different-ways)
- [Controlled access to camera, microphone, location](https://learn.microsoft.com/windows/uwp/packaging/app-capability-declarations), and other devices (with user consent)
- [Background tasks](https://learn.microsoft.com/windows/uwp/launch-resume/declare-background-tasks-in-the-application-manifest) (run when app is closed)
- [File type associations](https://learn.microsoft.com/windows/apps/desktop/modernize/desktop-to-uwp-extensions#integrate-with-file-explorer) (open `.xyz` files with your app)
- [Startup tasks](https://learn.microsoft.com/windows/apps/desktop/modernize/desktop-to-uwp-extensions#start-an-executable-file-when-users-log-into-windows) (launch at Windows login)
- [App services](https://learn.microsoft.com/windows/uwp/launch-resume/how-to-create-and-consume-an-app-service) (expose APIs to other apps)
- [Clean install/uninstall & auto-updates](https://learn.microsoft.com/windows/msix/overview)

## ✏️ Get started

Check out our getting started guides for step by step instructions of how to setup your environment, generate manifests, assets, and certificate, how to debug APIs that require package identity, and how to MSIX package your app.

<p>
  <a href="./docs/guides/winui.md">
    <img src="https://img.shields.io/bad
```
