Last active
May 14, 2024 08:25
-
-
Save markylaredo/4bd31b7aaf7ed27f90704fec90cd4380 to your computer and use it in GitHub Desktop.
.net core dev script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to display the menu | |
function show_menu { | |
echo "1. Run Project with 'dotnet watch --no-hot-reload'" | |
echo "2. Build Project with 'dotnet build'" | |
echo "3. Publish Project" | |
echo "4. Add Migration" | |
echo "5. Remove Migrations" | |
echo "6. Update Database" | |
echo "7. Drop Database" | |
echo "8. Generate Migration SQL Script" | |
echo "0. Exit" | |
} | |
# Function to publish for Linux | |
function publish_linux { | |
rm -rf ./publish/* && dotnet publish -c Release -r linux-x64 --self-contained --nologo --output ./publish -v n && current_datetime=$(date +"%Y-%m-%d_%H%M%S") && zip_filename=linx_publish_${current_datetime}.7z && 7z a -mx9 -r ${zip_filename} ./publish/* && rm -rf ./publish | |
} | |
function publish_windows { | |
rm -rf ./publish/* && dotnet publish -c Release -r win-x64 --self-contained --nologo --output ./publish -v n && current_datetime=$(date +"%Y-%m-%d_%H%M%S") && zip_filename=win_publish_${current_datetime}.7z && 7z a -mx9 -r ${zip_filename} ./publish/* && rm -rf ./publish | |
} | |
# Main loop | |
while true; do | |
show_menu | |
read -p "Choose an option (0-8): " choice | |
case $choice in | |
1) | |
echo "Running Project with 'dotnet watch --no-hot-reload'" | |
dotnet watch run --no-hot-reload | |
;; | |
2) | |
echo "Building project..." | |
dotnet build | |
;; | |
3) | |
echo "Which runtime do you want to publish for?" | |
echo "1. Linux" | |
echo "2. Windows" | |
read -p "Choose an option (1-2): " runtime_choice | |
case $runtime_choice in | |
1) | |
echo "Publishing for Linux..." | |
publish_linux | |
;; | |
2) | |
echo "Publishing for Windows..." | |
publish_windows | |
;; | |
*) | |
echo "Invalid choice. Please enter 1 for Linux or 2 for Windows." | |
;; | |
esac | |
;; | |
4) | |
read -p "Enter migration name: " migration_name | |
dotnet ef migrations add "$migration_name" -o Persistence/Migrations | |
;; | |
5) | |
echo "Removing Migrations..." | |
dotnet ef migrations remove -v | |
;; | |
6) | |
echo "Updating Database..." | |
dotnet ef database update -v | |
;; | |
7) | |
echo "Dropping Database (force)..." | |
dotnet ef database drop --force -v | |
;; | |
8) | |
echo "Generating Migration SQL Script..." | |
dotnet ef migrations script --output ./script.sql | |
echo "Migration SQL script generated successfully." | |
;; | |
0) | |
echo "Exiting..." | |
exit 0 | |
;; | |
*) | |
echo "Invalid choice. Please enter a number between 0 to 7." | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment