Last active
March 9, 2018 04:51
-
-
Save stknohg/3d86a34c0f3156c12f3c611cfbb15cef to your computer and use it in GitHub Desktop.
.NET Coreで単体テスト付きのプロジェクト(クラスライブラリ)を生成するスクリプト
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
# see : https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test | |
function New-CoreXUnitProject { | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Mandatory = $true)] | |
[string]$ProjectName | |
) | |
# Validations | |
try { | |
[void](Get-Command -Name 'dotnet' -ErrorAction Stop) | |
} catch { | |
Write-Error 'Failed to find dotnet command.' | |
return | |
} | |
$currentDir = Get-Location -PSProvider FileSystem | |
Push-Location -Path $currentDir | |
try { | |
# create solution root directory | |
$rootPath = Join-Path $currentDir $ProjectName | |
if (Test-Path $rootPath) { | |
Write-Error ("{0} is already exists." -f $rootPath) | |
return | |
} | |
[void](mkdir -Path $rootPath -Force) | |
# create solution | |
$currentDir = $rootPath | |
Set-Location $currentDir | |
dotnet new sln | |
# create source project | |
[void](mkdir -Path (Join-Path $currentDir $ProjectName) -Force) | |
Set-Location (Join-Path $currentDir $ProjectName) | |
dotnet new classlib | |
Set-Location $currentDir | |
dotnet sln add (Join-Path $currentDir ("{0}\{0}.csproj" -f $ProjectName)) | |
# create test project | |
$testProjectName = "{0}.Tests" -f $ProjectName | |
[void](mkdir -Path (Join-Path $currentDir $testProjectName) -Force) | |
Set-Location (Join-Path $currentDir $testProjectName) | |
dotnet new xunit | |
dotnet add reference (Join-Path $currentDir ("{0}\{0}.csproj" -f $ProjectName)) | |
Set-Location $currentDir | |
dotnet sln add (Join-Path $currentDir ("{0}\{0}.csproj" -f $testProjectName)) | |
} finally { | |
Pop-Location | |
} | |
} | |
# usage : | |
# cd [rootdir] | |
# New-CoreXUnitProject -PorjectName Sample |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment