Skip to content

Instantly share code, notes, and snippets.

@AlexKorsakov
Last active October 26, 2021 18:20
Show Gist options
  • Save AlexKorsakov/bea61d3b43cb90e790cdfb6c1cb67e3a to your computer and use it in GitHub Desktop.
Save AlexKorsakov/bea61d3b43cb90e790cdfb6c1cb67e3a to your computer and use it in GitHub Desktop.
DotnetSolutionCreator creates dotnet solution with console app faster than you do it by Visual Studio. Optionally, you can add a unit test project.
param (
[Parameter(Mandatory=$true, Position=1)]
[string]$name = "TestSolution",
[Alias('t')]
[Parameter(Mandatory=$false,Position=2)]
[switch]$isAddTestProject
)
New-Item -Path "." -Name $name -ItemType "directory"
Set-Location -Path $name
$slnPath = '{0}.sln' -f $name
$mainProjectName = '{0}/{0}.csproj' -f $name
dotnet new sln -n $name
dotnet new console -o $name
Write-Host "...Solution with name '$slnPath' created"
if ($isAddTestProject)
{
$testsFolderName = '{0}.Tests' -f $name
$testsProjectPath = '{0}/{0}.csproj' -f $testsFolderName
dotnet new nunit -n $testsFolderName
dotnet add $testsProjectPath reference $mainProjectName
Write-Host "...Tests project created"
}
dotnet sln $slnPath add (ls -r **/*.csproj)
dotnet new gitignore
Write-Host "...gitignore created"
Set-Location -Path ".\.."
@AlexKorsakov
Copy link
Author

.\create-sln.ps1 TestConsole -t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment