Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions .github/skills/building-code/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
---
name: building-code
description: >-
Instructions for restoring and building the WinForms repository.
Comment thread
Shyam-Gupta marked this conversation as resolved.
Use when asked how to restore NuGet packages, build the full solution,
build a single project, create packages, or troubleshoot build errors.
metadata:
author: dotnet-winforms
version: "1.0"
---

# Building the WinForms Repository

## Prerequisites

* Windows is required for WinForms runtime scenarios, test execution, and Visual
Studio workflows.
* Linux is supported for command-line restore/build only; use `build.sh`
instead of `build.cmd` / `Restore.cmd`.
* Visual Studio 2022 (for IDE builds) — see `WinForms.vsconfig` for required workloads.
* The repo-local .NET SDK (specified in `global.json`) is used automatically by
`build.cmd` and `Restore.cmd`. You do **not** need a machine-wide SDK install
for command-line builds.

---

## 1 Restore

Restoring downloads the repo-local SDK and all NuGet packages.

```
.\Restore.cmd
```

Under the hood this runs:

```powershell
eng\common\Build.ps1 -NativeToolsOnMachine -restore
```

You can pass any extra `Build.ps1` flags after `Restore.cmd`, e.g.
`.\Restore.cmd -configuration Release`.

---

## 2 Full Solution Build (preferred)

```
.\build.cmd
```

This restores **and** builds `Winforms.sln` in `Debug|Any CPU` by default.

Under the hood this runs:

```powershell
eng\common\Build.ps1 -NativeToolsOnMachine -restore -build -bl
```

### Common flags

| Flag | Short | Description |
|------|-------|-------------|
| `-configuration <Debug\|Release>` | `-c` | Build configuration (default: `Debug`) |
| `-platform <x86\|x64\|Any CPU>` | | Platform (default: `Any CPU`) |
| `-restore` | `-r` | Restore only |
| `-build` | `-b` | Build only (skip restore if already done) |
| `-rebuild` | | Clean + build |
| `-clean` | | Delete build artifacts |
| `-pack` | | Create NuGet packages (`Microsoft.Private.Winforms`) |
| `-bl` / `-binaryLog` | | Emit `artifacts\log\Debug\Build.binlog` |
| `-ci` | | CI mode (stricter warnings, signing, etc.) |
| `-test` | `-t` | Build **and** run unit tests |
| `-integrationTest` | | Build **and** run integration / functional tests |
Comment thread
Shyam-Gupta marked this conversation as resolved.

### Examples

```bash
# Release build
.\build.cmd -configuration Release

# Build and run unit tests
.\build.cmd -test

# Create NuGet package
.\build.cmd -pack
```

---

## 3 Optimized Building a Single Project (fast inner-loop)

Prefer rebuilding just the project(s) with recent changes by using the
standard `dotnet build` command, **after** at least one initial successful
full restore (via `.\Restore.cmd` or `.\build.cmd`).

This is **much** faster than building the whole solution.

```bash
# Build a single src project
dotnet build src\System.Windows.Forms\System.Windows.Forms.csproj

# Build a single test project
dotnet build src\test\unit\System.Windows.Forms\System.Windows.Forms.Tests.csproj

# Release configuration
dotnet build src\System.Windows.Forms\System.Windows.Forms.csproj -c Release
```

> **Tip:** The repo-local SDK must be on your `PATH`. Running `.\start-code.cmd`
> or `.\start-vs.cmd` prepends it automatically. From a plain terminal you can
> also run `.\Restore.cmd` first (it sets up the SDK).

---

## 4 Building from Visual Studio

1. Run `.\Restore.cmd` (one-time, or after SDK/package changes).
2. Run `.\start-vs.cmd` — opens `Winforms.sln` with the repo-local SDK on `PATH`.
3. Build normally (<kbd>Ctrl+Shift+B</kbd>).

## 5 Building from Visual Studio Code

1. (Optional) `.\Restore.cmd`
2. `.\start-code.cmd` — opens the workspace with the repo-local SDK on `PATH`.
3. Build from the integrated terminal: `.\build.cmd` or `dotnet build <project>`.

---

## Build Outputs

| Artifact | Location |
|----------|----------|
| Binaries | `artifacts\bin\<Project>\Debug\<tfm>\` |
| Logs | `artifacts\log\` |
| Binary log | `artifacts\log\Debug\Build.binlog` |
| Test results | `artifacts\TestResults\` |
| NuGet packages | `artifacts\packages\` |

Use the [MSBuild Structured Log Viewer](https://msbuildlog.com/) to inspect
`.binlog` files when troubleshooting build errors.

---

## Troubleshooting

* **Most errors are compile errors** — fix them as usual.
* **MSBuild task errors** — inspect `artifacts\log\Debug\Build.binlog`.
* **SDK version mismatch** — the repo pins its SDK in `global.json`;
run `.\Restore.cmd` to ensure the correct SDK is available.
* **VS preview features** — if using a non-Preview VS, enable
*Tools → Options → Environment → Preview Features →
Use previews of the .NET SDK*.
194 changes: 194 additions & 0 deletions .github/skills/download-sdk/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
---
name: download-sdk
description: >-
Instructions for downloading and installing .NET preview runtime versions
required by the WinForms repository. Use when test executables fail with
"framework not found" errors or when a specific .NET preview runtime
version needs to be installed.
metadata:
author: dotnet-winforms
version: "1.0"
---

# Downloading and Installing .NET Preview Runtimes

The WinForms repository targets **.NET preview** builds. Test executables and
built assemblies require a matching runtime version that may not be publicly
available on the official .NET download page. Use the internal CI feed URL
pattern below to download and install the exact version needed.

---

## 1 Determining the Required Version

The required runtime version can be found in multiple ways:

### From an error message

When a test executable cannot find its target framework, the error includes the
version:

```
Framework: 'Microsoft.NETCore.App', version '11.0.0-preview.4.26203.108' (x64)
```

### From runtimeconfig.json (programmatic — preferred)

Each test executable has a `.runtimeconfig.json` next to it that declares the
exact version required:

```powershell
$rc = Get-Content "artifacts\bin\System.Windows.Forms.Tests\Debug\net11.0-windows7.0\System.Windows.Forms.Tests.runtimeconfig.json" | ConvertFrom-Json
$version = $rc.runtimeOptions.framework.version
Write-Host "Required runtime: $version"
```

---

## 2 Download URL Pattern

Use the following base URL, replacing `{version}` with the full version string:

### x64 (64-bit) — required for standard test runs

```
https://ci.dot.net/public/Runtime/{version}/dotnet-runtime-{version}-win-x64.msi
```

### x86 (32-bit) — required for 32-bit test runs

```
https://ci.dot.net/public/Runtime/{version}/dotnet-runtime-{version}-win-x86.msi
```

### Example

For version `11.0.0-preview.4.26203.108`:

```
x64: https://ci.dot.net/public/Runtime/11.0.0-preview.4.26203.108/dotnet-runtime-11.0.0-preview.4.26203.108-win-x64.msi
x86: https://ci.dot.net/public/Runtime/11.0.0-preview.4.26203.108/dotnet-runtime-11.0.0-preview.4.26203.108-win-x86.msi
```

---

## 3 Download and Install (PowerShell)

```powershell
$version = "11.0.0-preview.4.26203.108" # ← replace with needed version

# Download both architectures
$url64 = "https://ci.dot.net/public/Runtime/$version/dotnet-runtime-$version-win-x64.msi"
$url86 = "https://ci.dot.net/public/Runtime/$version/dotnet-runtime-$version-win-x86.msi"
$msi64 = "$env:TEMP\dotnet-runtime-$version-win-x64.msi"
$msi86 = "$env:TEMP\dotnet-runtime-$version-win-x86.msi"

Invoke-WebRequest -Uri $url64 -OutFile $msi64 -UseBasicParsing
Invoke-WebRequest -Uri $url86 -OutFile $msi86 -UseBasicParsing

# Install (requires elevation)
Start-Process msiexec.exe -ArgumentList "/i `"$msi64`" /quiet /norestart" -Wait -Verb RunAs
Start-Process msiexec.exe -ArgumentList "/i `"$msi86`" /quiet /norestart" -Wait -Verb RunAs

# Verify installation
& "C:\Program Files\dotnet\dotnet.exe" --list-runtimes | Select-String $version

# Clean up
Remove-Item $msi64, $msi86 -ErrorAction SilentlyContinue
```

> **Important:** The `-Verb RunAs` flag triggers a UAC elevation prompt.
> Without it, the MSI install silently fails with exit code **1603**.

---

## 4 Verifying the Installation

After installation, verify the runtime is available:

```powershell
# x64
& "C:\Program Files\dotnet\dotnet.exe" --list-runtimes | Select-String $version

# x86
& "C:\Program Files (x86)\dotnet\dotnet.exe" --list-runtimes | Select-String $version

# Or check the shared framework directory directly
Get-ChildItem "C:\Program Files\dotnet\shared\Microsoft.NETCore.App" -Filter "$($version.Split('-')[0])*"
Get-ChildItem "C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App" -Filter "$($version.Split('-')[0])*"
```

---

## 5 Fully Automated: Detect, Download, and Install

This script reads the required version from any test executable's
`runtimeconfig.json`, downloads both architectures, and installs them:

```powershell
# Auto-detect version from the first test runtimeconfig found
$rc = Get-ChildItem "artifacts\bin\*Tests*\Debug\*\*.runtimeconfig.json" |
Select-Object -First 1
$version = (Get-Content $rc | ConvertFrom-Json).runtimeOptions.framework.version
Write-Host "Required runtime: $version"

# Check if already installed
$installed = & "C:\Program Files\dotnet\dotnet.exe" --list-runtimes 2>$null |
Select-String ([regex]::Escape($version))
if ($installed) {
Write-Host "Runtime $version is already installed."
return
}

# Download
$base = "https://ci.dot.net/public/Runtime/$version"
$msi64 = "$env:TEMP\dotnet-runtime-$version-win-x64.msi"
$msi86 = "$env:TEMP\dotnet-runtime-$version-win-x86.msi"
Invoke-WebRequest "$base/dotnet-runtime-$version-win-x64.msi" -OutFile $msi64 -UseBasicParsing
Invoke-WebRequest "$base/dotnet-runtime-$version-win-x86.msi" -OutFile $msi86 -UseBasicParsing

# Install (elevated)
Start-Process msiexec.exe -ArgumentList "/i `"$msi64`" /quiet /norestart" -Wait -Verb RunAs
Start-Process msiexec.exe -ArgumentList "/i `"$msi86`" /quiet /norestart" -Wait -Verb RunAs

# Verify
& "C:\Program Files\dotnet\dotnet.exe" --list-runtimes | Select-String $version

# Clean up
Remove-Item $msi64, $msi86 -ErrorAction SilentlyContinue
```

---

## 6 Alternative: Use the Repo-Local Runtime

The repository includes a local `.dotnet` folder (populated by `.\Restore.cmd`)
that may already have the required runtime. To use it instead of installing
system-wide:

```powershell
# From the repository root:
$env:DOTNET_ROOT = "$PWD\.dotnet"
$env:PATH = "$PWD\.dotnet;$env:PATH"
```

Check available versions:

```powershell
Get-ChildItem ".dotnet\shared\Microsoft.NETCore.App" | Select Name
```

> **Note:** The repo-local runtime works for running test executables but may
> not be picked up by `vstest.console.exe` or other external tools.

---

## 7 Troubleshooting

| Problem | Solution |
|---------|----------|
| MSI install fails with exit code **1603** | Run with `-Verb RunAs` for admin elevation |
| MSI install exits **0** but runtime not listed | The install ran without elevation and failed silently — retry with `-Verb RunAs` |
| Download returns **404** | Double-check the version string; the runtime may not be published to the CI feed yet |
| Test exe still says "framework not found" after install | Ensure the **architecture** matches (x64 vs x86); check that the test exe is looking for `Microsoft.NETCore.App` (not `Microsoft.WindowsDesktop.App` or `Microsoft.AspNetCore.App`) |
| Need `Microsoft.WindowsDesktop.App` | Replace `Runtime` with `WindowsDesktop` in the URL: `https://ci.dot.net/public/WindowsDesktop/{version}/windowsdesktop-runtime-{version}-win-x64.msi` |
Loading