Skip to content

Commit d4ea9cb

Browse files
committed
feat: Add constants and registry infrastructure
Phase 2 & 3 improvements from code review: Constants/: - MSBuildVersions.cs - VS version constants - Conditions.cs - Reusable condition expressions with fluent helpers Registry/: - UsingTasksRegistry.cs - Data-driven task registration (16 lines → 5) Updates: - SharedPropertyGroups now uses MSBuildVersions constants - Ready for BuildTransitiveTargetsFactory to adopt these patterns Benefits: - Self-documenting version numbers - Reusable conditions (30+ duplications → helpers) - Data-driven task registration - Easier to maintain and extend
1 parent f5bb793 commit d4ea9cb

3 files changed

Lines changed: 156 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
namespace JD.Efcpt.Build.Definitions.Constants;
2+
3+
/// <summary>
4+
/// Common MSBuild condition expressions used throughout the build definitions.
5+
/// Provides type-safe, reusable condition strings to eliminate duplication.
6+
/// </summary>
7+
public static class Conditions
8+
{
9+
/// <summary>
10+
/// Checks if EFCPT is enabled for the project.
11+
/// </summary>
12+
public const string EfcptEnabled = "'$(EfcptEnabled)' == 'true'";
13+
14+
/// <summary>
15+
/// Checks if the current project is a SQL database project.
16+
/// </summary>
17+
public const string IsSqlProject = "'$(_EfcptIsSqlProject)' == 'true'";
18+
19+
/// <summary>
20+
/// Checks if the current project is NOT a SQL database project.
21+
/// </summary>
22+
public const string IsNotSqlProject = "'$(_EfcptIsSqlProject)' != 'true'";
23+
24+
/// <summary>
25+
/// Checks if connection string mode is being used.
26+
/// </summary>
27+
public const string UseConnectionString = "'$(_EfcptUseConnectionString)' == 'true'";
28+
29+
/// <summary>
30+
/// Checks if direct DACPAC mode is being used.
31+
/// </summary>
32+
public const string UseDirectDacpac = "'$(_EfcptUseDirectDacpac)' == 'true'";
33+
34+
/// <summary>
35+
/// Checks if no DACPAC path is specified.
36+
/// </summary>
37+
public const string NoDacpac = "'$(EfcptDacpac)' == ''";
38+
39+
/// <summary>
40+
/// Checks if split outputs mode is enabled.
41+
/// </summary>
42+
public const string SplitOutputs = "'$(EfcptSplitOutputs)' == 'true'";
43+
44+
/// <summary>
45+
/// Checks if the EFCPT fingerprint has changed.
46+
/// </summary>
47+
public const string FingerprintChanged = "'$(_EfcptFingerprintChanged)' == 'true'";
48+
49+
/// <summary>
50+
/// Combines multiple conditions with AND logic.
51+
/// </summary>
52+
/// <param name="conditions">The conditions to combine.</param>
53+
/// <returns>A combined condition string.</returns>
54+
public static string And(params string[] conditions) =>
55+
string.Join(" and ", conditions);
56+
57+
/// <summary>
58+
/// Combines multiple conditions with OR logic.
59+
/// </summary>
60+
/// <param name="conditions">The conditions to combine.</param>
61+
/// <returns>A combined condition string.</returns>
62+
public static string Or(params string[] conditions) =>
63+
string.Join(" or ", conditions);
64+
65+
/// <summary>
66+
/// Creates a condition that checks if EFCPT is enabled AND another condition is true.
67+
/// </summary>
68+
/// <param name="condition">The additional condition.</param>
69+
/// <returns>A combined condition string.</returns>
70+
public static string EfcptEnabledAnd(string condition) =>
71+
And(EfcptEnabled, condition);
72+
73+
/// <summary>
74+
/// Creates a condition for EFCPT-enabled SQL projects.
75+
/// </summary>
76+
public static string EfcptEnabledSqlProject =>
77+
And(EfcptEnabled, IsSqlProject);
78+
79+
/// <summary>
80+
/// Creates a condition for EFCPT-enabled data access projects (not SQL projects).
81+
/// </summary>
82+
public static string EfcptEnabledDataAccess =>
83+
And(EfcptEnabled, IsNotSqlProject);
84+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace JD.Efcpt.Build.Definitions.Constants;
2+
3+
/// <summary>
4+
/// MSBuild version constants for task assembly resolution.
5+
/// Maps MSBuild versions to Visual Studio releases.
6+
/// </summary>
7+
public static class MSBuildVersions
8+
{
9+
/// <summary>
10+
/// MSBuild 18.0 - Visual Studio 2026 and later
11+
/// </summary>
12+
public const string VS2026 = "18.0";
13+
14+
/// <summary>
15+
/// MSBuild 17.14 - Visual Studio 2024 Update 14 and later
16+
/// </summary>
17+
public const string VS2024Update14 = "17.14";
18+
19+
/// <summary>
20+
/// MSBuild 17.12 - Visual Studio 2024 Update 12 and later
21+
/// </summary>
22+
public const string VS2024Update12 = "17.12";
23+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using JD.MSBuild.Fluent.Fluent;
2+
3+
namespace JD.Efcpt.Build.Definitions.Registry;
4+
5+
/// <summary>
6+
/// Centralized registry for all JD.Efcpt.Build custom MSBuild tasks.
7+
/// Automatically registers all task assemblies with MSBuild using a data-driven approach.
8+
/// </summary>
9+
public static class UsingTasksRegistry
10+
{
11+
/// <summary>
12+
/// All custom task names in the JD.Efcpt.Build.Tasks assembly.
13+
/// Adding a new task only requires adding its name to this array.
14+
/// </summary>
15+
private static readonly string[] TaskNames =
16+
[
17+
"AddSqlFileWarnings",
18+
"ApplyConfigOverrides",
19+
"CheckSdkVersion",
20+
"ComputeFingerprint",
21+
"DetectSqlProject",
22+
"EnsureDacpacBuilt",
23+
"FinalizeBuildProfiling",
24+
"InitializeBuildProfiling",
25+
"QuerySchemaMetadata",
26+
"RenameGeneratedFiles",
27+
"ResolveDbContextName",
28+
"ResolveSqlProjAndInputs",
29+
"RunEfcpt",
30+
"RunSqlPackage",
31+
"SerializeConfigProperties",
32+
"StageEfcptInputs"
33+
];
34+
35+
/// <summary>
36+
/// Registers all EFCPT custom tasks with MSBuild.
37+
/// Uses the resolved task assembly path from SharedPropertyGroups.
38+
/// </summary>
39+
/// <param name="t">The targets builder to register tasks with.</param>
40+
public static void RegisterAll(ITargetsBuilder t)
41+
{
42+
const string assemblyPath = "$(_EfcptTaskAssembly)";
43+
44+
foreach (var taskName in TaskNames)
45+
{
46+
t.UsingTask($"JD.Efcpt.Build.Tasks.{taskName}", assemblyPath);
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)