Public/New-Solution.ps1
<# .SYNOPSIS Assuming Visual Studio 2017.3 installed, will create a new C# solution in current or specified directory. .DESCRIPTION Will attempt to delete existing directory or halt if deletion fails. .PARAMETER name Name of the overall solution in upper camel case like "Zoo" or "ClassAction". Don't use "Solution" or "sln" as part of the name. .PARAMETER directory Defaults to current directory. Will create a solution folder inside this directory which is name parameter plus "Solution" .EXAMPLE C:\PS> New-Solution Zoo c:\code Creates a valid but empty Visual Studio solution c:\code\Zoo\ZooSolution\ZooSolution.sln .NOTES Author: Brian Woelfel Date: 2017/09/07 #> Function New-Solution() { param ([Parameter(Mandatory=$true)][string]$name, [Alias("dir")][string]$directory = "") if($directory -eq "") { $directory = (Get-Location) $directory = "$($directory)\$name" } [SolnInfo] $solnInfo = [SolnInfo]::new($name, $directory) if(Test-Path $solnInfo.solnDir) { Write-Host "### Remove old root directory $solnInfo.solnDir" Remove-Item -Recurse -Force $solnInfo.solnDir } if(-not(Test-Path $solnInfo.solnDir)) { Write-Host "### Make root directory $solnInfo.solnDir" New-Item $solnInfo.solnDir -ItemType directory } Write-Host "### Make new solution " $solnInfo.solnName " at " $solnInfo.solnDir &{dotnet new sln -n $solnInfo.solnName -o $solnInfo.solnDir} Confirm-LastExitCode $solnInfo.SaveConf() } |