This blog post will show you how to create an ASP.NET 6 application using PowerShell and also use the latest .NET SDK version installed on the machine.
It is good to create ASP.NET applications with PowerShell because it allows us to get the same results consistently when creating applications.
First, the following code gets the latest .NET SDK version installed on the system and uses it to create the application. The code also has a variable for the application name, which you only need to type once.
$temp = dotnet --list-sdks | select -Last 1 $mynetver = $temp.split() $mynetver $appname = "MyASPApp" dotnet new globaljson --sdk-version $mynetver --output $appname dotnet new mvc --no-https --output $appname --framework net6.0 dotnet new sln -o $appname dotnet sln $appname add $appname
To create the app, save the file as .PS1 and run in the folder you would like to create the application inside.