Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat SDK SQL Projects as first class citizen #2739

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/GUI/EFCorePowerTools/EFCorePowerToolsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace EFCorePowerTools
name: "Auto load based on rules",
expression: "CSharpConfig & (SingleProject | MultipleProjects) ",
termNames: new[] { "CSharpConfig", "SingleProject", "MultipleProjects" },
termValues: new[] { "ActiveProjectCapability:CSharp & CPS & !MSBuild.Sdk.SqlProj.BuildTSqlScript", VSConstants.UICONTEXT.SolutionHasSingleProject_string, VSConstants.UICONTEXT.SolutionHasMultipleProjects_string })]
termValues: new[] { "ActiveProjectCapability:CSharp & CPS", VSConstants.UICONTEXT.SolutionHasSingleProject_string, VSConstants.UICONTEXT.SolutionHasMultipleProjects_string })]
[ProvideMenuResource("Menus.ctmenu", 1)]
public sealed class EFCorePowerToolsPackage : AsyncPackage
{
Expand Down Expand Up @@ -533,7 +533,7 @@ private async void OnSqlProjectMenuBeforeQueryStatus(object sender, EventArgs e)

if (menuCommand.CommandID.ID == PkgCmdIDList.cmdidSqlprojCreate)
{
if (!project.FullPath.EndsWith(".sqlproj", StringComparison.OrdinalIgnoreCase))
if (!(await project.IsSqlDatabaseProjectAsync()))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static string Write(this ReverseEngineerUserOptions options, string proje
{
if (!string.IsNullOrEmpty(options.UiHint)
&& (options.UiHint.EndsWith(".sqlproj", System.StringComparison.OrdinalIgnoreCase)
|| options.UiHint.EndsWith(".csproj", System.StringComparison.OrdinalIgnoreCase)
|| options.UiHint.EndsWith(".dacpac", System.StringComparison.OrdinalIgnoreCase)))
{
options.UiHint = SqlProjHelper.SetRelativePathForSqlProj(options.UiHint, projectDirectory);
Expand Down
4 changes: 2 additions & 2 deletions src/GUI/Shared/Handlers/CliHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private async Task<bool> ChooseDataBaseConnectionAsync(DataApiBuilderOptions opt
databaseList = databaseList.Where(databaseList => Providers.GetDabProviders().Contains(databaseList.Value.DatabaseType))
.ToDictionary(databaseList => databaseList.Key, databaseList => databaseList.Value);

var dacpacList = await SqlProjHelper.GetDacpacFilesInActiveSolutionAsync();
var dacpacList = await SqlProjHelper.GetDacpacProjectsInActiveSolutionAsync();

var psd = package.GetView<IPickServerDatabaseDialog>();

Expand Down Expand Up @@ -205,7 +205,7 @@ private async Task<DatabaseConnectionModel> GetDatabaseInfoAsync(DataApiBuilderO
options.ConnectionString = dbInfo.ConnectionString;
options.DatabaseType = dbInfo.DatabaseType;

options.Dacpac = await SqlProjHelper.BuildSqlProjAsync(options.Dacpac);
options.Dacpac = await SqlProjHelper.BuildSqlProjectAsync(options.Dacpac);
if (string.IsNullOrEmpty(options.Dacpac))
{
VSHelper.ShowMessage(ReverseEngineerLocale.UnableToBuildSelectedDatabaseProject);
Expand Down
4 changes: 2 additions & 2 deletions src/GUI/Shared/Handlers/DabBuilderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private async Task<bool> ChooseDataBaseConnectionAsync(DataApiBuilderOptions opt
databaseList = databaseList.Where(databaseList => Providers.GetDabProviders().Contains(databaseList.Value.DatabaseType))
.ToDictionary(databaseList => databaseList.Key, databaseList => databaseList.Value);

var dacpacList = await SqlProjHelper.GetDacpacFilesInActiveSolutionAsync();
var dacpacList = await SqlProjHelper.GetDacpacProjectsInActiveSolutionAsync();

var psd = package.GetView<IPickServerDatabaseDialog>();

Expand Down Expand Up @@ -207,7 +207,7 @@ private async Task<DatabaseConnectionModel> GetDatabaseInfoAsync(DataApiBuilderO
options.ConnectionString = dbInfo.ConnectionString;
options.DatabaseType = dbInfo.DatabaseType;

options.Dacpac = await SqlProjHelper.BuildSqlProjAsync(options.Dacpac);
options.Dacpac = await SqlProjHelper.BuildSqlProjectAsync(options.Dacpac);
if (string.IsNullOrEmpty(options.Dacpac))
{
VSHelper.ShowMessage(ReverseEngineerLocale.UnableToBuildSelectedDatabaseProject);
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Shared/Handlers/DacpacAnalyzerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task GenerateAsync(string path, bool isConnectionString)
}
else
{
dacpacPath = await SqlProjHelper.BuildSqlProjAsync(path);
dacpacPath = await SqlProjHelper.BuildSqlProjectAsync(path);
}

await VS.StatusBar.ShowProgressAsync("Generating DACPAC Analysis report...", 2, 3);
Expand Down
4 changes: 2 additions & 2 deletions src/GUI/Shared/Handlers/DatabaseDiagramHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task GenerateAsync(string connectionName = null)

if (info.DatabaseModel.DatabaseType == DatabaseType.SQLServerDacpac)
{
connectionString = await SqlProjHelper.BuildSqlProjAsync(info.DatabaseModel.FilePath);
connectionString = await SqlProjHelper.BuildSqlProjectAsync(info.DatabaseModel.FilePath);
}

if (info.DatabaseModel.DataConnection != null)
Expand Down Expand Up @@ -77,7 +77,7 @@ private static List<string> GetSchemas(SchemaInfo[] schemas)
{
var vsDataHelper = new VsDataHelper();
var databaseList = await vsDataHelper.GetDataConnectionsAsync(package);
var dacpacList = await SqlProjHelper.GetDacpacFilesInActiveSolutionAsync();
var dacpacList = await SqlProjHelper.GetDacpacProjectsInActiveSolutionAsync();

if (!string.IsNullOrEmpty(connectionName) && databaseList != null && databaseList.Any())
{
Expand Down
4 changes: 2 additions & 2 deletions src/GUI/Shared/Handlers/ErDiagramHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private async Task<bool> ChooseDataBaseConnectionAsync(DataApiBuilderOptions opt
databaseList = databaseList.Where(databaseList => Providers.GetDabProviders().Contains(databaseList.Value.DatabaseType))
.ToDictionary(databaseList => databaseList.Key, databaseList => databaseList.Value);

var dacpacList = await SqlProjHelper.GetDacpacFilesInActiveSolutionAsync();
var dacpacList = await SqlProjHelper.GetDacpacProjectsInActiveSolutionAsync();

var psd = package.GetView<IPickServerDatabaseDialog>();

Expand Down Expand Up @@ -173,7 +173,7 @@ private async Task<DatabaseConnectionModel> GetDatabaseInfoAsync(DataApiBuilderO
options.ConnectionString = dbInfo.ConnectionString;
options.DatabaseType = dbInfo.DatabaseType;

options.Dacpac = await SqlProjHelper.BuildSqlProjAsync(options.Dacpac);
options.Dacpac = await SqlProjHelper.BuildSqlProjectAsync(options.Dacpac);
if (string.IsNullOrEmpty(options.Dacpac))
{
VSHelper.ShowMessage(ReverseEngineerLocale.UnableToBuildSelectedDatabaseProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,11 @@ private async Task<bool> ChooseDataBaseConnectionByUiHintAsync(ReverseEngineerOp
}
}

var dacpacList = await SqlProjHelper.GetDacpacFilesInActiveSolutionAsync();
if (dacpacList != null && dacpacList.Any() && !string.IsNullOrEmpty(options.UiHint)
&& options.UiHint.EndsWith(".sqlproj", StringComparison.OrdinalIgnoreCase))
var dacpacList = await SqlProjHelper.GetDacpacProjectsInActiveSolutionAsync();
if (dacpacList != null && dacpacList.Any() && !string.IsNullOrEmpty(options.UiHint))
{
var candidate = dacpacList
.Where(m => !string.IsNullOrWhiteSpace(m) && m.EndsWith(".sqlproj"))
.Where(m => !string.IsNullOrWhiteSpace(m))
.FirstOrDefault(m => m.Equals(options.UiHint, StringComparison.OrdinalIgnoreCase));

if (candidate != null)
Expand All @@ -390,7 +389,7 @@ private async Task<bool> ChooseDataBaseConnectionByUiHintAsync(ReverseEngineerOp
private async Task<bool> ChooseDataBaseConnectionAsync(ReverseEngineerOptions options, Project project)
{
var databaseList = await vsDataHelper.GetDataConnectionsAsync(package);
var dacpacList = await SqlProjHelper.GetDacpacFilesInActiveSolutionAsync();
var dacpacList = await SqlProjHelper.GetDacpacProjectsInActiveSolutionAsync();

var psd = package.GetView<IPickServerDatabaseDialog>();

Expand Down Expand Up @@ -474,7 +473,7 @@ private async Task<DatabaseConnectionModel> GetDatabaseInfoAsync(ReverseEngineer
options.ConnectionString = dbInfo.ConnectionString;
options.DatabaseType = dbInfo.DatabaseType;

options.Dacpac = await SqlProjHelper.BuildSqlProjAsync(options.Dacpac);
options.Dacpac = await SqlProjHelper.BuildSqlProjectAsync(options.Dacpac);
if (string.IsNullOrEmpty(options.Dacpac))
{
VSHelper.ShowMessage(ReverseEngineerLocale.UnableToBuildSelectedDatabaseProject);
Expand Down
20 changes: 6 additions & 14 deletions src/GUI/Shared/Helpers/SqlProjHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static string GetFullPathForSqlProj(string uiHint, string projectDirector
}

if (uiHint.EndsWith(".sqlproj", StringComparison.OrdinalIgnoreCase)
|| uiHint.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase)
|| uiHint.EndsWith(".dacpac", StringComparison.OrdinalIgnoreCase))
{
return PathHelper.GetAbsPath(uiHint, projectDirectory);
Expand All @@ -43,7 +44,7 @@ public static string GetFullPathForSqlProj(string uiHint, string projectDirector
return uiHint;
}

public static async Task<string[]> GetDacpacFilesInActiveSolutionAsync()
public static async Task<string[]> GetDacpacProjectsInActiveSolutionAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

Expand All @@ -59,22 +60,12 @@ public static async Task<string[]> GetDacpacFilesInActiveSolutionAsync()
continue;
}

if (item.FullPath.EndsWith(".sqlproj", StringComparison.OrdinalIgnoreCase))
if (await item.IsSqlDatabaseProjectAsync())
{
result.Add(item.FullPath);
continue;
}

if (await item.IsMsBuildSqlProjOrMsBuildSqlProjectAsync())
{
var dacpacPath = await item.GetDacpacPathAsync();

if (!string.IsNullOrEmpty(dacpacPath))
{
result.Add(dacpacPath);
}
}

try
{
await AddLinkedFilesAsync(result, item);
Expand All @@ -92,11 +83,12 @@ public static async Task<string[]> GetDacpacFilesInActiveSolutionAsync()

return result
.Where(s => s.EndsWith(".sqlproj", StringComparison.OrdinalIgnoreCase))
.Concat(result.Where(s => s.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase)))
.Concat(result.Where(s => s.EndsWith(".dacpac", StringComparison.OrdinalIgnoreCase)))
.ToArray();
}

public static async Task<string> BuildSqlProjAsync(string sqlprojPath)
public static async Task<string> BuildSqlProjectAsync(string sqlprojPath)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

Expand All @@ -113,7 +105,7 @@ public static async Task<string> BuildSqlProjAsync(string sqlprojPath)

if (!await VS.Build.ProjectIsUpToDateAsync(project))
{
var ok = await VS.Build.BuildProjectAsync(project, BuildAction.Rebuild);
var ok = await VS.Build.BuildProjectAsync(project, BuildAction.Build);

if (!ok)
{
Expand Down
13 changes: 4 additions & 9 deletions src/GUI/Shared/ViewModels/DatabaseConnectionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public string DisplayName
return "<null>";
}

if (FilePath.EndsWith(".sqlproj", StringComparison.InvariantCultureIgnoreCase))
if (FilePath.EndsWith(".sqlproj", StringComparison.InvariantCultureIgnoreCase)
|| FilePath.EndsWith(".csproj", StringComparison.InvariantCultureIgnoreCase))
{
return $"{Path.GetFileNameWithoutExtension(FilePath)} (.dacpac)";
return $"{Path.GetFileNameWithoutExtension(FilePath)} (SQL Project)";
}

if (FilePath.EndsWith(".dacpac", StringComparison.InvariantCultureIgnoreCase))
Expand Down Expand Up @@ -97,13 +98,7 @@ public string ToolTip
{
return "<null>";
}

if (FilePath.EndsWith(".sqlproj", StringComparison.InvariantCultureIgnoreCase))
{
return FilePath;
}

if (FilePath.EndsWith(".dacpac", StringComparison.InvariantCultureIgnoreCase))
else
{
return FilePath;
}
Expand Down
1 change: 0 additions & 1 deletion src/GUI/Shared/ViewModels/PickServerDatabaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ private void Loaded_Executed()
!string.IsNullOrWhiteSpace(c.FilePath)
&& !string.IsNullOrEmpty(UiHint)
&& SelectedDatabaseConnection == null
&& c.FilePath.EndsWith(".sqlproj", StringComparison.OrdinalIgnoreCase)
&& c.FilePath.Equals(UiHint, StringComparison.OrdinalIgnoreCase));

if (candidate != null)
Expand Down