Scripts/DotnetCore.ps1


function CreateNewSolution
{
    <#
    .SYNOPSIS
    Create a new c# solution.
    .EXAMPLE
    Open a powershell console. Import the cmx module.
    Go the directory where you want to create the solution.
    The run this command:
    > CreateNewSolution -Name MySolution
    #>

    param
    (
        [string]$name = "Solution"
    )
    
    $rootPath = "$(Get-Location)"
    $slnName = $Name
    $projectName = "Project"
    $slnPath = "$rootPath\$slnName"

    if(Test-Path -Path $slnPath -PathType Container)
    {
        Write-Host "A solution is already created under $slnPath."
    }
    else
    {
        New-Item -Path $rootPath -Name $slnName -ItemType "directory" | Out-Null
    
        & cd $slnName
        & dotnet new sln -n "$slnName"
        & dotnet new console -n $projectName
        Write-Host "Location: $(Get-Location)"
        & dotnet sln "$slnName.sln" add "./$projectName/$projectName.csproj"
        
        Write-Host "Solution has been successfully created under $slnPath."
    }
}