| name | .NET nanoFramework Agent | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| description | Agent instructions for generating, reviewing, and modifying C# code for .NET nanoFramework samples on constrained embedded devices. | ||||||||||||
| tools |
|
This repository targets .NET nanoFramework, which runs C# on constrained embedded devices (for example ESP32, STM32, and others).
When generating, reviewing, or modifying code in this repo, follow these rules:
- Do not assume an API exists just because it is available in desktop/main .NET.
- Always verify availability in the nanoFramework API browser:
- If an API is not available, propose a nanoFramework-compatible alternative.
- Use existing samples in this repo as the primary source for implementation patterns, coding style, and project structure.
- Before introducing a new approach, check if an equivalent pattern already exists in:
- Keep solutions simple and aligned with embedded constraints (memory, CPU, storage, networking reliability).
- Assume APIs are simplified even when naming aligns with main .NET.
- Avoid desktop-only features, heavy abstractions, reflection-heavy code, or dependencies that are unlikely to run on embedded targets.
- Prefer deterministic, lightweight implementations suitable for microcontrollers.
- Always consider the constraints of the target hardware when proposing solutions.
- Generics, async patterns, and certain language features are not yet supported on nanoFramework.
- nanoFramework supports many IoT device bindings.
- For hardware-specific code, check existing bindings and guidance first:
- Reuse existing bindings and samples rather than creating custom low-level implementations when a supported binding exists.
- Keep allocations and background work minimal.
- Be explicit about timeouts, retries, and error handling for I/O and networking.
- Favor clear, maintainable code that can run reliably on constrained devices.
- When in doubt, choose the simpler implementation.
- Explicitly mention when a proposal depends on API availability or board-specific capabilities.
- Add concise notes about what should be verified on target hardware.
- Always include a build step when changes affect code, project files, or package references.
- Follow the nanoFramework VS Code extension build model: use
nuget restore+msbuild. - Build scope selection:
- If a matching
*.slnexists for the changed sample, build the solution (preferred, same as extension workflow). - If no solution exists, build the target
*.nfprojdirectly. - When targeting a project, use the project path and project system path defined/imported by the
.nfproj.
- If a matching
- Preferred command sequence (PowerShell):
nuget restore <path-to-solution-or-project>msbuild <path-to-solution-or-project> /p:platform="Any CPU" /p:Configuration=Release /verbosity:minimal
- If
msbuildis not onPATH, resolve it first (for example withvswhereon Windows), then run the same restore/build steps. - Windows example to resolve
MSBuild.exewithvswhereand build:$msbuild = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -products * -latest -prerelease -requires Microsoft.Component.MSBuild -find "MSBuild\**\Bin\amd64\MSBuild.exe" | Select-Object -First 1& $msbuild <path-to-solution-or-project> /p:platform="Any CPU" /p:Configuration=Release /verbosity:minimal
- If build fails:
- Report the exact error output.
- Propose a minimal fix.
- Re-run the same
nuget restore+msbuildsequence after the fix.
- In final results, summarize:
- Which solution/project was built.
- Whether
nuget restore+msbuildsucceeded. - Any remaining manual hardware validation steps (deployment/flash/runtime checks).
- Do not default to
dotnet testfor nanoFramework projects. - For unit tests, follow the nanoFramework Test Platform workflow (
nanoFramework.TestFramework,nanoFramework.UnitTestLauncher,nanoFramework.TestAdapter). - Identify unit test projects by checking
.nfprojmetadata such as:<IsTestProject>true</IsTestProject><TestProjectType>UnitTest</TestProjectType>
- Ensure a
.runsettingsfile exists (oftennano.runsettings) and includes nanoFramework adapter settings. - Test discovery/execution flow:
- Build first (
nuget restore+msbuild) so tests are discovered. - Run tests through Visual Studio / Test Explorer (or equivalent VS test host integration).
- For hardware execution, set
<IsRealHardware>True</IsRealHardware>in.runsettings.
- Build first (
- Pipeline/automation flow:
- Use
vstest.Console.exewithnanoFramework.TestAdapter.dll. - Keep test adapter and test framework package versions aligned.
- Use
- When reporting test outcomes, include:
- Which test project and runsettings file were used.
- Whether tests ran on emulator/simulated mode or real hardware.
- Pass/fail/skip summary and any device-specific constraints.