Successfully migrated GitHub Actions workflows from using nuget.exe (with Mono) to the modern dotnet CLI approach using a simplified JavaScript module.
- File:
convert-nuget-to-dotnet.mjs - Runtime: Bun (no package.json required)
- Purpose: Automated script to convert existing workflows
- Features:
- Detects and converts
nuget source Addtodotnet nuget add source - Converts
nuget pushtodotnet nuget push - Adds
actions/setup-dotnet@v4to workflows that need .NET SDK - Removes deprecated
nuget/setup-nuget@v1action - Backup Management: Creates and manages backup files
- Error Handling: Robust error handling with graceful degradation
- Cross-Platform: Works on any platform with bun runtime
- Detects and converts
- Before: Used
nuget source Addandnuget pushcommands - After: Uses
dotnet nuget add sourceanddotnet nuget push - Authentication: Updated to use
--store-password-in-clear-textflag for GitHub Package Registry - Added:
actions/setup-dotnet@v4with .NET 8.0.x
- Added:
actions/setup-dotnet@v4for consistency (though not strictly needed for this workflow)
- Added:
actions/setup-dotnet@v4for consistency
- Added:
actions/setup-dotnet@v4for consistency
- Modern Approach: Uses the official .NET CLI instead of Mono-based nuget.exe
- Better Performance: Native .NET CLI is faster than Mono-based nuget.exe
- Consistent Tooling: Aligns with modern .NET development practices
- Future-Proof: Uses the recommended approach for .NET 8.0+
- Simplified Setup: No need for separate nuget setup action
- Cross-Platform: JavaScript module works on any platform with bun
- Reliable: Simplified approach ensures successful conversion
| Old Command | New Command |
|---|---|
nuget source Add -Name "GitHub" -Source "..." -UserName ... -Password ... |
dotnet nuget add source ... --name GitHub --username ... --password ... --store-password-in-clear-text |
nuget push **/*.nupkg -Source "GitHub" -SkipDuplicate |
dotnet nuget push **/*.nupkg --source GitHub --skip-duplicate |
The conversion script was tested and successfully:
- ✅ Detected workflow files in
.github/workflows/ - ✅ Converted nuget commands to dotnet CLI equivalents
- ✅ Added setup-dotnet actions where needed
- ✅ Preserved GitHub secrets and authentication
- ✅ Maintained proper YAML formatting
- ✅ Backup Management: Proper backup file handling
- ✅ Error Recovery: Graceful error handling
- ✅ Bun Runtime: Successfully runs with
bun convert-nuget-to-dotnet.mjs
convert-nuget-to-dotnet.mjs(new JavaScript module).github/workflows/csharp.yml.github/workflows/AutoMerge.yml.github/workflows/cpp-test.yml.github/workflows/deploy-cpp.yml
# Install bun (if not already installed)
curl -fsSL https://bun.sh/install | bash
# Run the conversion script
bun convert-nuget-to-dotnet.mjs- Focused on core conversion functionality
- Removed complex YAML validation that caused issues
- Maintained essential backup and error handling
- Reliable and predictable behavior
- Comprehensive error handling with try-catch blocks
- Backup file management with proper cleanup
- Graceful degradation on file system errors
- Detailed error messages and status updates
- JavaScript module (.mjs) works on any platform
- No dependencies beyond bun runtime
- No package.json required
- Self-contained script
- Review: The changes have been committed and pushed to the repository
- Test: Run the workflows to ensure they work correctly with the new dotnet CLI commands
- Monitor: Watch for any issues in the GitHub Package Registry publishing
- Document: Update any documentation that references the old nuget.exe approach
- Reuse: The JavaScript module can be used for other repositories needing similar migration
This migration addresses Issue #120 for migrating from nuget.exe to dotnet CLI.