Skip to content

Commit 6ca784c

Browse files
committed
Update SolutionBuilder with target framework and configuration arguments.
1 parent 8ed47dc commit 6ca784c

11 files changed

Lines changed: 185 additions & 42 deletions

File tree

.github/workflows/build-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ jobs:
1515
uses: actions/setup-dotnet@v1
1616
with:
1717
dotnet-version: 9.0.101
18+
- name: Setup .NET Core
19+
uses: actions/setup-dotnet@v1
20+
with:
21+
dotnet-version: 8.0.101
1822
- name: Install dependencies
1923
run: dotnet restore
2024
- name: Build

.github/workflows/build-pr.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ jobs:
1515
uses: actions/setup-dotnet@v1
1616
with:
1717
dotnet-version: 9.0.101
18+
- name: Setup .NET Core
19+
uses: actions/setup-dotnet@v1
20+
with:
21+
dotnet-version: 8.0.101
1822
- name: Install dependencies
1923
run: dotnet restore
2024
- name: Build

CodeQuality.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Global
137137
GlobalSection(NestedProjects) = preSolution
138138
{9785BB59-DC3D-46CF-B45C-DF4DBE6F0B2F} = {5B172423-1455-41CB-8D81-7DCFCFF8855D}
139139
{46DE472E-6200-47A1-9874-3B54952DFF81} = {5B172423-1455-41CB-8D81-7DCFCFF8855D}
140-
{B4ED680E-2B7B-4DFE-87E6-A3CBEE75C3DD} = {5B172423-1455-41CB-8D81-7DCFCFF8855D}
140+
{B4ED680E-2B7B-4DFE-87E6-A3CBEE75C3DD} = {57F5BB2E-CD03-470B-BF16-31FE02A386B1}
141141
{6FB11F33-250F-4DE8-934A-F63CDC8976D6} = {B1962CF8-DE8C-42AA-BC4E-99E99D722E26}
142142
{E4FAC4E6-2853-4464-B78F-6BAB619EEF8D} = {B1962CF8-DE8C-42AA-BC4E-99E99D722E26}
143143
{4D9D7FB7-CB50-4F61-92E7-A2CD669B15A7} = {1D5021C0-2423-494A-98F6-71AB937CDF8B}

src/libs/SoloX.CodeQuality.Playwright/PlaywrightDriver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private static void InstallPlaywright()
101101

102102
var lockFile = Path.Combine(localApplicationData, "PlaywrightInstallLock");
103103

104-
var timeout = 60;
104+
var timeout = 60 * 3;
105105

106106
while (!TryWriteLockFile(lockFile))
107107
{

src/libs/SoloX.CodeQuality.Test.Helpers/DotnetHelper.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,41 @@ public static bool Restore(string projectPath, out ProcessResult processResult,
3939
}
4040

4141
public static bool Build(string projectPath, out ProcessResult processResult,
42-
Action<StringDictionary>? environmentVariablesHandler = null)
42+
Action<StringDictionary>? environmentVariablesHandler = null, string? configuration = null)
4343
{
44-
return Dotnet(projectPath, BUILD, out processResult, environmentVariablesHandler);
44+
var configurationArg = string.IsNullOrEmpty(configuration) ? string.Empty : $" --configuration {configuration}";
45+
46+
return Dotnet(projectPath, $"{BUILD}{configurationArg}", out processResult, environmentVariablesHandler);
4547
}
4648

4749
public static bool Test(string projectPath, out ProcessResult processResult,
48-
Action<StringDictionary>? environmentVariablesHandler = null)
50+
Action<StringDictionary>? environmentVariablesHandler = null, string? configuration = null)
4951
{
50-
return Dotnet(projectPath, TEST, out processResult, environmentVariablesHandler);
52+
var configurationArg = string.IsNullOrEmpty(configuration) ? string.Empty : $" --configuration {configuration}";
53+
54+
return Dotnet(projectPath, $"{TEST}{configurationArg}", out processResult, environmentVariablesHandler);
5155
}
5256

5357
public static bool Publish(string projectPath, out ProcessResult processResult,
58+
Action<StringDictionary>? environmentVariablesHandler = null, string? configuration = null)
59+
{
60+
var configurationArg = string.IsNullOrEmpty(configuration) ? string.Empty : $" --configuration {configuration}";
61+
62+
return Dotnet(projectPath, $"{PUBLISH}{configurationArg}", out processResult, environmentVariablesHandler);
63+
}
64+
65+
public static bool New(string path, string template, string? framework, string output, out ProcessResult processResult,
5466
Action<StringDictionary>? environmentVariablesHandler = null)
5567
{
56-
return Dotnet(projectPath, PUBLISH, out processResult, environmentVariablesHandler);
68+
return string.IsNullOrEmpty(framework)
69+
? Dotnet(path, $"{NEW} {template} --output {output}", out processResult, environmentVariablesHandler)
70+
: Dotnet(path, $"{NEW} {template} --output {output} --framework {framework}", out processResult, environmentVariablesHandler);
5771
}
5872

5973
public static bool New(string path, string template, string output, out ProcessResult processResult,
6074
Action<StringDictionary>? environmentVariablesHandler = null)
6175
{
62-
return Dotnet(path, $"{NEW} {template} --output {output}", out processResult, environmentVariablesHandler);
76+
return New(path, template, null, output, out processResult, environmentVariablesHandler);
6377
}
6478

6579
public static bool NewSln(string path, string solutionName, out ProcessResult processResult,
@@ -87,15 +101,17 @@ public static bool AddReference(string path, string projectFilePath, string proj
87101
}
88102

89103
public static bool Run(string projectPath, out ProcessResult processResult,
90-
Action<StringDictionary>? environmentVariablesHandler = null)
104+
Action<StringDictionary>? environmentVariablesHandler = null, string? configuration = null)
91105
{
92-
return Run(projectPath, string.Empty, out processResult, environmentVariablesHandler);
106+
return Run(projectPath, string.Empty, out processResult, environmentVariablesHandler, configuration);
93107
}
94108

95109
public static bool Run(string projectPath, string args, out ProcessResult processResult,
96-
Action<StringDictionary>? environmentVariablesHandler = null)
110+
Action<StringDictionary>? environmentVariablesHandler = null, string? configuration = null)
97111
{
98-
return Dotnet(projectPath, $"{RUN} {args}", out processResult, environmentVariablesHandler);
112+
var configurationArg = string.IsNullOrEmpty(configuration) ? string.Empty : $" --configuration {configuration}";
113+
114+
return Dotnet(projectPath, $"{RUN}{configurationArg} {args}", out processResult, environmentVariablesHandler);
99115
}
100116

101117
internal static bool NewToolManifest(string path, out ProcessResult processResult,

src/libs/SoloX.CodeQuality.Test.Helpers/Solution/ISolution.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,44 @@ namespace SoloX.CodeQuality.Test.Helpers.Solution
1313
/// </summary>
1414
public interface ISolution
1515
{
16+
/// <summary>
17+
/// Name of the solution to build.
18+
/// </summary>
19+
string SolutionName { get; }
20+
21+
/// <summary>
22+
/// Path of the solution to build.
23+
/// </summary>
24+
string SolutionPath { get; }
25+
26+
/// <summary>
27+
/// Default configuration.
28+
/// </summary>
29+
string DefaultConfiguration { get; }
30+
1631
/// <summary>
1732
/// Build solution.
1833
/// </summary>
1934
/// <param name="project">Project to build or null to build all solution.</param>
35+
/// <param name="configuration">Configuration to use.</param>
2036
/// <returns>Process result.</returns>
21-
ProcessResult Build(string? project = null);
37+
ProcessResult Build(string? project = null, string? configuration = null);
2238

2339
/// <summary>
2440
/// Test solution.
2541
/// </summary>
2642
/// <param name="project">Project to run.</param>
43+
/// <param name="configuration">Configuration to use.</param>
2744
/// <returns>Process result.</returns>
28-
ProcessResult Run(string? project = null);
45+
ProcessResult Run(string? project = null, string? configuration = null);
2946

3047
/// <summary>
3148
/// Test solution.
3249
/// </summary>
3350
/// <param name="project">Project to test or null to run all solution tests.</param>
51+
/// <param name="configuration">Configuration to use.</param>
3452
/// <returns>Process result.</returns>
35-
ProcessResult Test(string? project = null);
53+
ProcessResult Test(string? project = null, string? configuration = null);
3654

3755
/// <summary>
3856
/// Run a Dotnet tool.
@@ -42,5 +60,20 @@ public interface ISolution
4260
/// <param name="project">Project where to run the tool or null to run from solution folder.</param>
4361
/// <returns>Process result.</returns>
4462
ProcessResult RunTool(string toolName, string? toolArgs = null, string? project = null);
63+
64+
/// <summary>
65+
/// Get the project path.
66+
/// </summary>
67+
/// <param name="project">Project name.</param>
68+
/// <returns>The project path.</returns>
69+
string GetProjectPath(string project);
70+
71+
/// <summary>
72+
/// Get the project binary path.
73+
/// </summary>
74+
/// <param name="project">Project name.</param>
75+
/// <param name="configuration">Configuration to use.</param>
76+
/// <returns>The project binary path.</returns>
77+
string GetProjectBinaryPath(string project, string? configuration = null);
4578
}
4679
}

src/libs/SoloX.CodeQuality.Test.Helpers/Solution/Impl/ProjectConfiguration.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ public ProjectConfiguration(
2323
SolutionBuilder solutionBuilder,
2424
string projectName,
2525
string template,
26+
string? framework,
2627
Action<IProjectConfiguration> configuration)
2728
{
2829
this.solutionBuilder = solutionBuilder;
2930
ProjectName = projectName;
3031
Template = template;
31-
32+
Framework = framework;
3233
ProjectFilePath = Path.Combine(projectName, $"{projectName}.csproj");
3334
ProjectPath = projectName;
3435

@@ -55,10 +56,15 @@ public ProjectConfiguration(
5556
/// </summary>
5657
public string Template { get; }
5758

59+
/// <summary>
60+
/// Project Target Framework (default if null).
61+
/// </summary>
62+
public string? Framework { get; }
63+
5864
public void Build()
5965
{
6066
SolutionBuilder.DotnetCall<ProjectError>((out ProcessResult processResult) =>
61-
DotnetHelper.New(this.solutionBuilder.SolutionPath, Template, ProjectName, out processResult)
67+
DotnetHelper.New(this.solutionBuilder.SolutionPath, Template, Framework, ProjectName, out processResult)
6268
);
6369

6470
this.configuration(this);

src/libs/SoloX.CodeQuality.Test.Helpers/Solution/SolutionBuilder.cs

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/tests/SoloX.CodeQuality.PreReleaseTestTool/SoloX.CodeQuality.PreReleaseTestTool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Nullable>enable</Nullable>
1010

1111
<PackAsTool>true</PackAsTool>
12-
<ToolCommandName>prerealsetesttool</ToolCommandName>
12+
<ToolCommandName>prereleasetesttool</ToolCommandName>
1313

1414
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1515

0 commit comments

Comments
 (0)