This repository provides build wrapper tools for developing Windows Desktop applications from WSL (Windows Subsystem for Linux). The wrapper solves the common issue where WSL's .NET runtime lacks Windows Desktop components required for WPF/WinForms applications.
Windows Desktop applications targeting net8.0-windows require the Windows Desktop runtime, which is not available in WSL's .NET installation. This wrapper bridges WSL to Windows .NET via cmd.exe, allowing you to develop and build from your preferred Linux environment while using the full Windows .NET stack.
A comprehensive build wrapper that executes .NET commands through Windows cmd.exe while maintaining full output visibility in your WSL terminal.
- Cross-platform path handling: Automatically converts WSL paths to Windows format
- Full command coverage: Supports all common .NET CLI operations
- Output preservation: Shows complete build output, warnings, and errors
- Multiple build configurations: Debug, Release, Verbose, Quiet modes
- Test execution: Runs test suites with proper Windows Desktop runtime
IMPORTANT: Before first use, edit build-wsl.sh and change line 31:
# Change this line:
echo "Building ProjectName using Windows .NET from WSL..."
# To your actual project name:
echo "Building YourActualProjectName using Windows .NET from WSL..."Replace ProjectName with your Visual Studio project or solution name for clearer output messages.
# Make script executable (first time only)
chmod +x build-wsl.sh
# Basic operations
./build-wsl.sh build # Build the solution
./build-wsl.sh clean # Clean build artifacts
./build-wsl.sh restore # Restore NuGet packages
./build-wsl.sh rebuild # Clean and rebuild
# Build variations
./build-wsl.sh verbose # Build with detailed output
./build-wsl.sh quiet # Build with minimal output
./build-wsl.sh release # Build release configuration
# Testing
./build-wsl.sh test # Run all tests
# Help
./build-wsl.sh # Show usage information- Path Conversion: Uses
wslpath -wto convert WSL paths to Windows format - Command Execution: Executes commands via
cmd.exe /cin the Windows environment - Output Streaming: Preserves all .NET CLI output, colors, and formatting
- Error Propagation: Maintains exit codes for proper CI/CD integration
Ensures shell scripts have correct LF line endings for WSL compatibility. Windows text editors often introduce CRLF line endings that break bash script execution.
$'\r': command not founderrorssyntax error near unexpected tokenin bash scripts- Script execution failures due to Windows line endings
# Make script executable (first time only)
chmod +x validate-line-endings.sh
# Check line endings
./validate-line-endings.sh
# Check and fix automatically
./validate-line-endings.sh --fixπ Checking line endings in shell scripts...
β
LF line endings: ./build-wsl.sh
β CRLF line endings found in: ./other-script.sh
β οΈ Found 1 files with CRLF line endings.
π‘ Run './validate-line-endings.sh --fix' to automatically convert them to LF.- Clone or download these scripts to your project root
- Configure project name in
build-wsl.sh(line 31) - Make scripts executable:
chmod +x build-wsl.sh validate-line-endings.sh
- Validate line endings:
./validate-line-endings.sh --fix
- Build your project:
./build-wsl.sh build
# This fails in WSL for Windows Desktop apps:
dotnet build
# Error: Framework 'Microsoft.WindowsDesktop.App' is not available# This works by using Windows .NET:
./build-wsl.sh build
# Successfully builds using Windows Desktop runtime- WSL 2 with .NET SDK installed
- Windows with .NET SDK including Windows Desktop runtime
- Git configured for cross-platform development:
git config core.autocrlf false git config core.safecrlf warn
The wrapper works with any .NET project structure:
- Single projects (
.csproj) - Solutions (
.sln) - Multi-project solutions
- Test projects
- Class libraries with Windows dependencies
# Check line endings
./validate-line-endings.sh
# Fix if needed
./validate-line-endings.sh --fix# Use verbose output for debugging
./build-wsl.sh verbose# Ensure scripts are executable
chmod +x *.shThe wrapper automatically handles path conversion, but if you encounter issues:
- Ensure you're running from the project root directory
- Check that Windows .NET is properly installed
- Verify WSL can access Windows drives
- Always use the wrapper for building Windows Desktop applications in WSL
- Validate line endings before committing shell scripts
- Use verbose mode when debugging build issues
- Keep scripts in project root for easy access
- Commit
.gitattributesto enforce consistent line endings:*.sh text eol=lf *.bash text eol=lf
Add these tasks to .vscode/tasks.json:
{
"label": "Build (WSL)",
"type": "shell",
"command": "./build-wsl.sh",
"args": ["build"],
"group": "build"
}Use in GitHub Actions or other CI systems:
- name: Build Windows Desktop App
run: ./build-wsl.sh build# Run all tests
./build-wsl.sh test
# Check both build and line endings
./validate-line-endings.sh && ./build-wsl.sh testThis wrapper enables seamless Windows Desktop application development from WSL while maintaining the full .NET development experience.