@@ -24,7 +24,9 @@ namespace SoloX.CodeQuality.Test.Helpers.Solution
2424 /// </summary>
2525 public class SolutionBuilder
2626 {
27+ private const string DefaultConfiguration = "Debug" ;
2728 private const string DefaultPackageFolder = "Packages" ;
29+
2830 private static readonly Action < INugetConfigConfiguration > DefaultNugetConfigConfigurationHandler =
2931 configuration => configuration . UsePackageSources ( s =>
3032 {
@@ -101,7 +103,24 @@ public SolutionBuilder WithNugetConfig(
101103 /// <returns>Self.</returns>
102104 public SolutionBuilder WithProject ( string projectName , string template , Action < IProjectConfiguration > configuration )
103105 {
104- var projectConfiguration = new ProjectConfiguration ( this , projectName , template , configuration ) ;
106+ var projectConfiguration = new ProjectConfiguration ( this , projectName , template , null , configuration ) ;
107+
108+ this . projectConfigurations . Add ( projectName , projectConfiguration ) ;
109+
110+ return this ;
111+ }
112+
113+ /// <summary>
114+ /// Generate the solution with a project named with the given projectName.
115+ /// </summary>
116+ /// <param name="projectName">Name of the project to create.</param>
117+ /// <param name="template">Project Template to use (like 'classlib', 'xunit'...).</param>
118+ /// <param name="framework">Target framework to use on the new project.</param>
119+ /// <param name="configuration">Project configuration.</param>
120+ /// <returns>Self.</returns>
121+ public SolutionBuilder WithProject ( string projectName , string template , string framework , Action < IProjectConfiguration > configuration )
122+ {
123+ var projectConfiguration = new ProjectConfiguration ( this , projectName , template , framework , configuration ) ;
105124
106125 this . projectConfigurations . Add ( projectName , projectConfiguration ) ;
107126
@@ -129,7 +148,8 @@ public SolutionBuilder WithDotnetTools(Action<IDotnetToolsConfiguration> configu
129148 /// <summary>
130149 /// Build the solution and all its projects.
131150 /// </summary>
132- public ISolution Build ( )
151+ /// <param name="defaultConfiguration">Default configuration to use in the solution (Debug by default).</param>
152+ public ISolution Build ( string defaultConfiguration = DefaultConfiguration )
133153 {
134154 Directory . CreateDirectory ( this . Root ) ;
135155
@@ -181,7 +201,7 @@ public ISolution Build()
181201 ) ;
182202 }
183203
184- return new Solution ( this , projectPathMap ) ;
204+ return new Solution ( this , projectPathMap , defaultConfiguration ) ;
185205 }
186206 catch ( Exception )
187207 {
@@ -214,31 +234,42 @@ private class Solution : ISolution
214234 private readonly SolutionBuilder solutionBuilder ;
215235 private readonly IReadOnlyDictionary < string , string > projectPathMap ;
216236
217- public Solution ( SolutionBuilder solutionBuilder , IReadOnlyDictionary < string , string > projectPathMap )
237+ public Solution ( SolutionBuilder solutionBuilder , IReadOnlyDictionary < string , string > projectPathMap , string defaultConfiguration )
218238 {
219239 this . solutionBuilder = solutionBuilder ;
220240 this . projectPathMap = projectPathMap ;
241+ this . DefaultConfiguration = defaultConfiguration ;
221242 }
222243
223- public ProcessResult Build ( string ? project = null )
244+ public string SolutionName => this . solutionBuilder . SolutionName ;
245+
246+ public string SolutionPath => this . solutionBuilder . SolutionPath ;
247+
248+ public string DefaultConfiguration { get ; }
249+
250+ public ProcessResult Build ( string ? project = null , string ? configuration = null )
224251 {
252+ var selectedConfiguration = string . IsNullOrEmpty ( configuration ) ? this . DefaultConfiguration : configuration ;
253+
225254 return string . IsNullOrEmpty ( project )
226255 ? DotnetCall < SolutionError > ( ( out ProcessResult processResult ) =>
227- DotnetHelper . Build ( this . solutionBuilder . SolutionPath , out processResult , this . solutionBuilder . SetupVariables )
256+ DotnetHelper . Build ( this . solutionBuilder . SolutionPath , out processResult , this . solutionBuilder . SetupVariables , selectedConfiguration )
228257 )
229258 : DotnetCall < ProjectError > ( ( out ProcessResult processResult ) =>
230- DotnetHelper . Build ( GetProjectPath ( project ) , out processResult , this . solutionBuilder . SetupVariables )
259+ DotnetHelper . Build ( GetProjectPath ( project ) , out processResult , this . solutionBuilder . SetupVariables , selectedConfiguration )
231260 ) ;
232261 }
233262
234- public ProcessResult Run ( string ? project = null )
263+ public ProcessResult Run ( string ? project = null , string ? configuration = null )
235264 {
265+ var selectedConfiguration = string . IsNullOrEmpty ( configuration ) ? this . DefaultConfiguration : configuration ;
266+
236267 return string . IsNullOrEmpty ( project )
237268 ? DotnetCall < SolutionError > ( ( out ProcessResult processResult ) =>
238- DotnetHelper . Run ( this . solutionBuilder . SolutionPath , out processResult , this . solutionBuilder . SetupVariables )
269+ DotnetHelper . Run ( this . solutionBuilder . SolutionPath , out processResult , this . solutionBuilder . SetupVariables , selectedConfiguration )
239270 )
240271 : DotnetCall < ProjectError > ( ( out ProcessResult processResult ) =>
241- DotnetHelper . Run ( GetProjectPath ( project ) , out processResult , this . solutionBuilder . SetupVariables )
272+ DotnetHelper . Run ( GetProjectPath ( project ) , out processResult , this . solutionBuilder . SetupVariables , selectedConfiguration )
242273 ) ;
243274 }
244275
@@ -253,18 +284,20 @@ public ProcessResult RunTool(string toolName, string? toolArgs, string? project
253284 ) ;
254285 }
255286
256- public ProcessResult Test ( string ? project = null )
287+ public ProcessResult Test ( string ? project = null , string ? configuration = null )
257288 {
258289 var path = string . IsNullOrEmpty ( project )
259290 ? this . solutionBuilder . SolutionPath
260291 : GetProjectPath ( project ) ;
261292
293+ var selectedConfiguration = string . IsNullOrEmpty ( configuration ) ? this . DefaultConfiguration : configuration ;
294+
262295 return DotnetCall < TestError > ( ( out ProcessResult processResult ) =>
263- DotnetHelper . Test ( path , out processResult , this . solutionBuilder . SetupVariables )
296+ DotnetHelper . Test ( path , out processResult , this . solutionBuilder . SetupVariables , selectedConfiguration )
264297 ) ;
265298 }
266299
267- private string GetProjectPath ( string project )
300+ public string GetProjectPath ( string project )
268301 {
269302 if ( this . projectPathMap . TryGetValue ( project , out var projectPath ) )
270303 {
@@ -273,6 +306,13 @@ private string GetProjectPath(string project)
273306
274307 throw new SolutionBuilderException < SolutionError > ( $ "Could not find project { project } ") ;
275308 }
309+
310+ public string GetProjectBinaryPath ( string project , string ? configuration = null )
311+ {
312+ var selectedConfiguration = string . IsNullOrEmpty ( configuration ) ? this . DefaultConfiguration : configuration ;
313+
314+ return Path . Combine ( GetProjectPath ( project ) , "bin" , selectedConfiguration ) ;
315+ }
276316 }
277317 }
278318}
0 commit comments