@@ -77,7 +77,11 @@ function New-Project {
7777 # Parameter help description
7878 [Parameter (Mandatory = $true )]
7979 [String ]
80- $solutionFile
80+ $solutionFile ,
81+
82+ [Parameter (Mandatory = $true )]
83+ [string ]
84+ $projectGroupName
8185 )
8286
8387 dotnet new xunit - n $projectName - o $folder -f $framework -- no- restore -- force | Out-Null
@@ -87,7 +91,12 @@ function New-Project {
8791 dotnet add $folder package -- no- restore coverlet.msbuild | Out-Null
8892 dotnet add $folder package -- no- restore Verify.Xunit | Out-Null
8993
90- dotnet sln $solutionFile add - s ' tests' $folder | Out-Null
94+ $targetFolder = ' tests'
95+ if ($projectGroupName -ne " " ) {
96+ $targetFolder = " src/$ ( $projectGroupName.ToLower ()) /$ ( $targetFolder ) "
97+ }
98+
99+ dotnet sln $solutionFile add - s $targetFolder $folder | Out-Null
91100 }
92101 }
93102
@@ -103,6 +112,7 @@ function New-Project {
103112 $setFramework = $true
104113 $createProjectReadMe = $false
105114 $projectGroup = " "
115+ $projectGroupName = " "
106116
107117 switch ($ProjectType ) {
108118 ' Library' {
@@ -167,23 +177,26 @@ function New-Project {
167177 }
168178 }
169179
180+ $projectGroupStart = $ProjectName.IndexOf (' .' )
181+ if ($EnableProjectGrouping -eq $true -and $projectGroupStart -ne -1 ) {
182+ $projectGroupStart += 1
170183
171- if ($EnableProjectGrouping -eq $true ) {
172- $projectGroupStart = $ProjectName.IndexOf (' .' )
173-
174- if ($EnableAdvProjectGrouping -eq $true ) {
175- $projectGroupEnd = $ProjectName.IndexOf (' .' , $projectGroupStart + 1 )
176- $projectGroupName = $ProjectName.Substring ($projectGroupStart + 1 , $projectGroupEnd - $projectGroupStart )
184+ $projectGroupEnd = $ProjectName.IndexOf (' .' , $projectGroupStart )
185+ if ($EnableAdvProjectGrouping -eq $true -and $projectGroupEnd -ne -1 ) {
186+ $projectGroupName = $ProjectName.Substring ($projectGroupStart , $projectGroupEnd - $projectGroupStart )
177187 } else {
178- $projectGroupName = $ProjectName.Substring ($projectGroupStart + 1 )
188+ $projectGroupName = $ProjectName.Substring ($projectGroupStart )
179189 }
180190 $projectGroup = " src/$ ( $projectGroupName.ToLower ()) /"
181191 }
182192
183193 $ProjectFolder = New-Item - Path " $ ( $projectGroup ) $ ( $targetFolder ) \$ ( $ProjectName ) " - ItemType Directory - Force
194+ if ($projectGroupName -ne " " ) {
195+ $targetFolder = " src/$ ( $projectGroupName.ToLower ()) /$ ( $targetFolder ) "
196+ }
184197
185198 $createParameters = ' new' , $projectSdk , ' -n' , $ProjectName , ' -o' , $ProjectFolder , ' --force'
186- if ($setFramework -eq $true ) {
199+ if ($EnableAdvProjectGrouping -eq $true -and $ setFramework -eq $true ) {
187200 $createParameters += ' -f' , $Framework
188201 }
189202 & dotnet $createParameters $additionalCreateParameters | Out-Null
@@ -204,13 +217,13 @@ function New-Project {
204217 if ($DisableUnitTests -eq $false ) {
205218 $ProjectNameUnitTests = " $ ( $ProjectName ) .Tests.Unit"
206219 $ProjectFolderUnitTests = New-Item - Path " $ ( $projectGroup ) tests\$ ( $ProjectNameUnitTests ) " - ItemType Directory - Force
207- New-TestProject $ProjectNameUnitTests $ProjectFolderUnitTests $ProjectFolder $Framework $SolutionFile
220+ New-TestProject $ProjectNameUnitTests $ProjectFolderUnitTests $ProjectFolder $Framework $SolutionFile $projectGroupName
208221 }
209222
210223 if ($DisableIntegrationTests -eq $false ) {
211224 $ProjectNameIntegrationTests = " $ ( $ProjectName ) .Tests.Integration"
212225 $ProjectFolderIntegrationTests = New-Item - Path " $ ( $projectGroup ) tests\$ ( $ProjectNameIntegrationTests ) " - ItemType Directory - Force
213- New-TestProject $ProjectNameIntegrationTests $ProjectFolderIntegrationTests $ProjectFolder $Framework $SolutionFile
226+ New-TestProject $ProjectNameIntegrationTests $ProjectFolderIntegrationTests $ProjectFolder $Framework $SolutionFile $projectGroupName
214227 }
215228 }
216229
0 commit comments