What problem does it solve?
Migrating MSBuild's Windows interop code from hand-written [DllImport] declarations to CsWin32 source-generated PInvoke.* calls involves many subtle rules: blittable signatures, FEATURE_WINDOWSINTEROP gating, error-handling parity, and source-build compatibility. This Skill encodes those rules so migrations stay correct and CI-clean.
Core Features & Use Cases
- DllImport Replacement: Replace
[DllImport] declarations and hand-written structs/enums/constants with CsWin32-generated PInvoke.* calls and typed enums like HRESULT, HANDLE, and WIN32_ERROR.
- Dual Guard Pattern: Apply
#if FEATURE_WINDOWSINTEROP plus runtime IsWindows checks correctly, and select the right guard for multi-TFM, net472-only, or .NET-only scenarios.
- Source-Build Verification: Run both normal and
DotNetBuildSourceOnly=true builds to catch IDE0005, IDE0051, CA1823, and CS1587 warnings treated as errors in CI.
- Use Case: When porting a Windows API call such as
GetFileAttributesEx in MSBuild, use this Skill to generate the blittable CsWin32 call, preserve the original SetLastError/PreserveSig error contract, and verify the source build compiles cleanly.
Quick Start
Migrate this [DllImport] declaration to CsWin32 PInvoke with proper FEATURE_WINDOWSINTEROP gating and error-handling parity.