diff --git a/src/GUI/EFCorePowerTools/EFCorePowerToolsPackage.cs b/src/GUI/EFCorePowerTools/EFCorePowerToolsPackage.cs index 83688414c..c2f20085a 100644 --- a/src/GUI/EFCorePowerTools/EFCorePowerToolsPackage.cs +++ b/src/GUI/EFCorePowerTools/EFCorePowerToolsPackage.cs @@ -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 { @@ -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; } diff --git a/src/GUI/Shared/Extensions/ReverseEngineerUserOptionsExtensions.cs b/src/GUI/Shared/Extensions/ReverseEngineerUserOptionsExtensions.cs index b3b5614f7..a37a27023 100644 --- a/src/GUI/Shared/Extensions/ReverseEngineerUserOptionsExtensions.cs +++ b/src/GUI/Shared/Extensions/ReverseEngineerUserOptionsExtensions.cs @@ -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); diff --git a/src/GUI/Shared/Handlers/CliHandler.cs b/src/GUI/Shared/Handlers/CliHandler.cs index e864429dd..1cc4b9472 100644 --- a/src/GUI/Shared/Handlers/CliHandler.cs +++ b/src/GUI/Shared/Handlers/CliHandler.cs @@ -132,7 +132,7 @@ private async Task 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(); @@ -205,7 +205,7 @@ private async Task 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); diff --git a/src/GUI/Shared/Handlers/DabBuilderHandler.cs b/src/GUI/Shared/Handlers/DabBuilderHandler.cs index 01a1eec0b..d9655e7e0 100644 --- a/src/GUI/Shared/Handlers/DabBuilderHandler.cs +++ b/src/GUI/Shared/Handlers/DabBuilderHandler.cs @@ -134,7 +134,7 @@ private async Task 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(); @@ -207,7 +207,7 @@ private async Task 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); diff --git a/src/GUI/Shared/Handlers/DacpacAnalyzerHandler.cs b/src/GUI/Shared/Handlers/DacpacAnalyzerHandler.cs index eb40ede04..468f994cf 100644 --- a/src/GUI/Shared/Handlers/DacpacAnalyzerHandler.cs +++ b/src/GUI/Shared/Handlers/DacpacAnalyzerHandler.cs @@ -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); diff --git a/src/GUI/Shared/Handlers/DatabaseDiagramHandler.cs b/src/GUI/Shared/Handlers/DatabaseDiagramHandler.cs index ddede6d1a..03922cc1e 100644 --- a/src/GUI/Shared/Handlers/DatabaseDiagramHandler.cs +++ b/src/GUI/Shared/Handlers/DatabaseDiagramHandler.cs @@ -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) @@ -77,7 +77,7 @@ private static List 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()) { diff --git a/src/GUI/Shared/Handlers/ErDiagramHandler.cs b/src/GUI/Shared/Handlers/ErDiagramHandler.cs index aeccf1bc3..63318b8ed 100644 --- a/src/GUI/Shared/Handlers/ErDiagramHandler.cs +++ b/src/GUI/Shared/Handlers/ErDiagramHandler.cs @@ -104,7 +104,7 @@ private async Task 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(); @@ -173,7 +173,7 @@ private async Task 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); diff --git a/src/GUI/Shared/Handlers/ReverseEngineer/ReverseEngineerHandler.cs b/src/GUI/Shared/Handlers/ReverseEngineer/ReverseEngineerHandler.cs index 3008a8d9d..c08fa2749 100644 --- a/src/GUI/Shared/Handlers/ReverseEngineer/ReverseEngineerHandler.cs +++ b/src/GUI/Shared/Handlers/ReverseEngineer/ReverseEngineerHandler.cs @@ -369,12 +369,11 @@ private async Task 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) @@ -390,7 +389,7 @@ private async Task ChooseDataBaseConnectionByUiHintAsync(ReverseEngineerOp private async Task 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(); @@ -474,7 +473,7 @@ private async Task 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); diff --git a/src/GUI/Shared/Helpers/SqlProjHelper.cs b/src/GUI/Shared/Helpers/SqlProjHelper.cs index 8fa8c7fdc..35082d919 100644 --- a/src/GUI/Shared/Helpers/SqlProjHelper.cs +++ b/src/GUI/Shared/Helpers/SqlProjHelper.cs @@ -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); @@ -43,7 +44,7 @@ public static string GetFullPathForSqlProj(string uiHint, string projectDirector return uiHint; } - public static async Task GetDacpacFilesInActiveSolutionAsync() + public static async Task GetDacpacProjectsInActiveSolutionAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); @@ -59,22 +60,12 @@ public static async Task 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); @@ -92,11 +83,12 @@ public static async Task 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 BuildSqlProjAsync(string sqlprojPath) + public static async Task BuildSqlProjectAsync(string sqlprojPath) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); @@ -113,7 +105,7 @@ public static async Task 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) { diff --git a/src/GUI/Shared/ViewModels/DatabaseConnectionModel.cs b/src/GUI/Shared/ViewModels/DatabaseConnectionModel.cs index a13c4d0f2..7ab0f66ac 100644 --- a/src/GUI/Shared/ViewModels/DatabaseConnectionModel.cs +++ b/src/GUI/Shared/ViewModels/DatabaseConnectionModel.cs @@ -67,9 +67,10 @@ public string DisplayName return ""; } - 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)) @@ -97,13 +98,7 @@ public string ToolTip { return ""; } - - if (FilePath.EndsWith(".sqlproj", StringComparison.InvariantCultureIgnoreCase)) - { - return FilePath; - } - - if (FilePath.EndsWith(".dacpac", StringComparison.InvariantCultureIgnoreCase)) + else { return FilePath; } diff --git a/src/GUI/Shared/ViewModels/PickServerDatabaseViewModel.cs b/src/GUI/Shared/ViewModels/PickServerDatabaseViewModel.cs index 327d13801..23eef2475 100644 --- a/src/GUI/Shared/ViewModels/PickServerDatabaseViewModel.cs +++ b/src/GUI/Shared/ViewModels/PickServerDatabaseViewModel.cs @@ -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)