-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectSqlProject.cs
More file actions
74 lines (63 loc) · 2.46 KB
/
DetectSqlProject.cs
File metadata and controls
74 lines (63 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace JD.Efcpt.Build.Tasks;
/// <summary>
/// MSBuild task that detects whether the current project is a SQL database project.
/// Uses the SqlProjectDetector to check for SDK-based projects first, then falls back to property-based detection.
/// </summary>
// Note: Fully qualifying Task to avoid ambiguity with System.Threading.Tasks.Task
public sealed class DetectSqlProject : Microsoft.Build.Utilities.Task
{
/// <summary>
/// Gets or sets the full path to the project file.
/// </summary>
[Required]
public string? ProjectPath { get; set; }
/// <summary>
/// Gets or sets the SqlServerVersion property (for legacy SSDT detection).
/// </summary>
public string? SqlServerVersion { get; set; }
/// <summary>
/// Gets or sets the DSP property (for legacy SSDT detection).
/// </summary>
public string? DSP { get; set; }
/// <summary>
/// Gets a value indicating whether the project is a SQL project.
/// </summary>
[Output]
public bool IsSqlProject { get; private set; }
/// <summary>
/// Executes the task to detect if the project is a SQL database project.
/// </summary>
/// <returns>True if the task executes successfully; otherwise, false.</returns>
public override bool Execute()
{
if (string.IsNullOrWhiteSpace(ProjectPath))
{
Log.LogError("ProjectPath is required.");
return false;
}
// First, check if project uses a modern SQL SDK via SDK attribute
var usesModernSdk = SqlProjectDetector.IsSqlProjectReference(ProjectPath);
if (usesModernSdk)
{
IsSqlProject = true;
Log.LogMessage(MessageImportance.Low,
"Detected SQL project via SDK attribute: {0}", ProjectPath);
return true;
}
// Fall back to property-based detection for legacy SSDT projects
var hasLegacyProperties = !string.IsNullOrEmpty(SqlServerVersion) || !string.IsNullOrEmpty(DSP);
if (hasLegacyProperties)
{
IsSqlProject = true;
Log.LogMessage(MessageImportance.Low,
"Detected SQL project via MSBuild properties (legacy SSDT): {0}", ProjectPath);
return true;
}
IsSqlProject = false;
Log.LogMessage(MessageImportance.Low,
"Not a SQL project: {0}", ProjectPath);
return true;
}
}