Last active
November 20, 2021 18:26
-
-
Save benyblack/559e3f8ed11f779a6ad3c379738acad8 to your computer and use it in GitHub Desktop.
A script for creating a new solution for dotnet
This file contains 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
bold=$(tput bold) | |
normal=$(tput sgr0) | |
read -p "New solution name: " slnname | |
# Create directory | |
mkdir $slnname | |
cd $slnname | |
# Create solution and directories | |
dotnet new sln > /dev/null 2>&1 | |
mkdir src | |
mkdir tests | |
# Create projects | |
addnew="yes" | |
while [ $addnew = "yes" ] | |
do | |
# Create project | |
echo "" | |
echo "Adding a project ... " | |
echo "Default project type is ${bold}classlib${normal}, but you may need ${bold}console${normal} or ${bold}mvc${normal} " | |
echo "List of templates for ${bold}dotnet new${normal} can be seen by using: ${bold}dotnet new --list${normal}" | |
echo "This will add a xUnit project in ${bold}tests${normal} folder" | |
echo "" | |
read -p "New project name: " prjname | |
read -p "New project type [classlib]: " prjtype | |
prjtype=${prjtype:-classlib} | |
cd src | |
echo "Creating the project ${bold}$prjname${normal} ..." | |
dotnet new $prjtype -n $prjname > /dev/null 2>&1 | |
cd .. | |
# Create Test project | |
cd tests | |
echo "Creating the test project ${bold}$prjname.Tests${normal} ..." | |
dotnet new xunit -n $prjname.Tests > /dev/null 2>&1 | |
cd $prjname.Tests | |
echo "Adding reference of ${bold}$prjname${normal} to the test project ..." | |
# Add related project reference to the test project | |
dotnet add reference ../../src/$prjname > /dev/null 2>&1 | |
# Add projects to solution | |
cd .. | |
cd .. | |
echo "Adding ${bold}$prjname${normal} & ${bold}$prjname.Tests${normal} to the solution ..." | |
dotnet sln add tests/$prjname.Tests > /dev/null 2>&1 | |
dotnet sln add src/$prjname > /dev/null 2>&1 | |
echo "Done." | |
echo "" | |
# Check if user wants to add another project | |
read -p "Add another project? [yes]/no: " addnew | |
addnew=${addnew:-yes} | |
done | |
# run build | |
echo "Building the solution ..." | |
dotnet build > /dev/null 2>&1 | |
echo "" | |
echo "=============================" | |
echo " Solution ${bold}$slnname${normal} is ready! " | |
echo "=============================" | |
echo "" | |
# add ReadMe | |
read -p "Add ReadMe? [yes]/no: " addreadme | |
addreadme=${addreadme:-yes} | |
if [ $addreadme = "yes" ] || [ $addreadme = "y" ] | |
then | |
echo "## $slnname\n This is a new solution. Please add some information here." > ReadMe.md | |
echo "Done." | |
fi | |
# add git | |
echo "" | |
read -p "Would you like to add ${bold}gitignore${normal} and initialize ${bold}git${normal}? [yes]/no: " addgit | |
addgit=${addgit:-yes} | |
if [ $addgit == "yes" ] || [ $addgit == "y" ] | |
then | |
echo "Adding gitignore ..." | |
dotnet new gitignore > /dev/null 2>&1 | |
echo "Initializing git ..." | |
git init > /dev/null 2>&1 | |
echo "Done." | |
fi | |
# open in vscode | |
echo "" | |
read -p "Open in vscode? [yes]/no: " openvscode | |
openvscode=${openvscode:-yes} | |
if [ $openvscode == "yes" ] || [ $openvscode == "y" ] | |
then | |
code . | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment