Skip to content

Commit

Permalink
Enable database dgml schema from a .dacpac (#2045)
Browse files Browse the repository at this point in the history
fixes #2042
  • Loading branch information
ErikEJ authored Dec 13, 2023
1 parent 17dc4da commit f8e2027
Show file tree
Hide file tree
Showing 3 changed files with 330 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/GUI/EFCorePowerTools/EFCorePowerTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@
<VSCTCompile Include="EFCorePowerToolsPackage.es.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
</VSCTCompile>
<VSCTCompile Include="EFCorePowerToolsPackage.fr.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
</VSCTCompile>
<VSCTCompile Include="EFCorePowerToolsPackage.it.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
</VSCTCompile>
Expand Down
312 changes: 312 additions & 0 deletions src/GUI/EFCorePowerTools/EFCorePowerToolsPackage.fr.vsct
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!--This is the file that defines the IDs for all the commands exposed by VisualStudio. -->
<Extern href="stdidcmd.h" />

<!--This header contains the command ids for the menus provided by the shell. -->
<Extern href="vsshlids.h" />

<Include href="KnownImageIds.vsct"/>

<!--The Commands section is where we the commands, menus and menu groups are defined.
This section uses a Guid to identify the package that provides the command defined inside it. -->
<Commands package="guidDbContextPackagePkg">
<Groups>
<Group guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenuGroup" priority="0x0100">
<Parent guid="guidDbContextPackageCmdSet" id="IDM_VS_CTXT_PROJNODE" />
</Group>

<Group guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenuItemsGroup" priority="0x0100">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenu" />
</Group>

<Group guid="guidDbContextPackageCmdSet" id="cmdidEdmMigrationMenuItemsGroup" priority="0x0150">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenu" />
</Group>

<Group guid="guidDbContextPackageCmdSet" id="cmdidEdmViewMenuItemsGroup" priority="0x0200">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenu" />
</Group>

<Group guid="guidDbContextPackageCmdSet" id="cmdidEdmDatabaseMenuItemsGroup" priority="0x0500">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenu" />
</Group>

<Group guid="guidDbContextPackageCmdSet" id="cmdidEdmCompareMenuItemsGroup" priority="0x0600">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenu" />
</Group>

<Group guid="guidDbContextPackageCmdSet" id="cmdidEdmAboutMenuItemsGroup" priority="0x0800">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenu" />
</Group>

<Group guid="guidReverseEngineerMenu" id="idReverseEngineerMenuGroup" priority="0x0100">
<Parent guid="guidReverseEngineerMenu" id="idReverseEngineerMenu" />
</Group>

<Group guid="guidVSPackageCommandProjectContextMenuCmdSet" id="MyGroupForCommands" />
</Groups>

<Menus>

<Menu guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenu" priority="0x0100" type="Menu">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenuGroup" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>EF Core Power Tools</CommandName>
<ButtonText>EF Core Power Tools</ButtonText>
</Strings>
</Menu>

<Menu guid="guidDbContextPackageCmdSet" id="cmdidEdmMenu" priority="0x0100" type="Menu">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmMenuGroup" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>EF Core Power Tools</CommandName>
<ButtonText>EF Core Power Tools</ButtonText>
</Strings>
</Menu>

<Menu guid="guidReverseEngineerMenu" id="idReverseEngineerMenu" priority="0x0100" type="Menu">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>EF Core Power Tools - Reverse Engineer</CommandName>
<ButtonText>EF Core Power Tools - Reverse Engineer</ButtonText>
</Strings>
</Menu>

</Menus>

<Buttons>

<Button guid="guidDbContextPackageCmdSet" id="cmdidReverseEngineerCodeFirst" priority="0x0100" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="DatabaseConfigurationFile" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidReverseEngineerCodeFirst</CommandName>
<ButtonText>Reverse Engineer</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidMigrationStatus" priority="0x0100" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmMigrationMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="GenerateChangeScript" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidMigrationStatus</CommandName>
<ButtonText>Migrations Tool (preview)</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidAbout" priority="0x0900" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmAboutMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="StatusHelpOutline" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidAbout</CommandName>
<ButtonText>About</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidOptions" priority="0x0700" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmAboutMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="Settings" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidOptions</CommandName>
<ButtonText>Options</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidT4Drop" priority="0x0250" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmViewMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="Template" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidT4Drop</CommandName>
<ButtonText>Add T4 Scaffolding Templates</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidDgmlBuild" priority="0x0200" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmViewMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="NewDiagram" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidDgmlNuget</CommandName>
<ButtonText>Add DbContext Diagram</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidSqlBuild" priority="0x0300" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmViewMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="SQLQueryChecked" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidSqlBuild</CommandName>
<ButtonText>View DbContext DDL SQL</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidDebugViewBuild" priority="0x0400" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmViewMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="ExportScript" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidDebugViewBuild</CommandName>
<ButtonText>View DbContext as DebugView</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidDgmlNuget" priority="0x0500" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmViewMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="PackageDeployment" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidDgmlNuget</CommandName>
<ButtonText>Add AsDgml() extension</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidDbCompare" priority="0x0900" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmCompareMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="CompareSchemas" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidDbCompare</CommandName>
<ButtonText>Compare DbContext to database</ButtonText>
</Strings>
</Button>

<Button guid="guidDbContextPackageCmdSet" id="cmdidDbDgml" priority="0x0800" type="Button">
<Parent guid="guidDbContextPackageCmdSet" id="cmdidEdmDatabaseMenuItemsGroup" />
<Icon guid="ImageCatalogGuid" id="DatabaseAuditSpecification" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidDbDgml</CommandName>
<ButtonText>Visualize Database Schema (preview)</ButtonText>
</Strings>
</Button>
<Button guid="guidReverseEngineerMenu" id="cmdidReverseEngineerEdit" priority="0x0100" type="Button">
<Parent guid="guidReverseEngineerMenu" id="idReverseEngineerMenuGroup" />
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<Strings>
<CommandName>EF Core Power Tools - Edit</CommandName>
<ButtonText>EF Core Power Tools - Edit</ButtonText>
</Strings>
</Button>

<Button guid="guidReverseEngineerMenu" id="cmdidReverseEngineerRefresh" priority="0x0100" type="Button">
<Parent guid="guidReverseEngineerMenu" id="idReverseEngineerMenuGroup" />
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<Strings>
<CommandName>EF Core Power Tools - Refresh</CommandName>
<ButtonText>EF Core Power Tools - Refresh</ButtonText>
</Strings>
</Button>

<Button guid="guidVSPackageCommandProjectContextMenuCmdSet" id="Command1Id" type="Button">
<Icon guid="ImageCatalogGuid" id="DatabaseScript" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<Strings>
<ButtonText>Create EF Core DbContext...</ButtonText>
</Strings>
</Button>

</Buttons>

</Commands>

<CommandPlacements>

<CommandPlacement guid="guidDbContextPackageCmdSet" id="cmdidEdmProjectMenuGroup" priority="0x100">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE" />
</CommandPlacement>

<CommandPlacement guid="guidReverseEngineerMenu" id="idReverseEngineerMenuGroup" priority="0x100">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
</CommandPlacement>

<CommandPlacement guid="guidVSPackageCommandProjectContextMenuCmdSet" id="MyGroupForCommands" priority="0x0001">
<!-- The parent of the group will be the project context menu -->
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE"/>
</CommandPlacement>

<CommandPlacement guid="guidVSPackageCommandProjectContextMenuCmdSet" id="Command1Id" priority="0x100" >
<Parent guid="guidVSPackageCommandProjectContextMenuCmdSet" id="MyGroupForCommands"/>
</CommandPlacement>
</CommandPlacements>

<Symbols>
<!-- This is the package guid. -->
<GuidSymbol name="guidDbContextPackagePkg" value="{f4c4712c-ceae-4803-8e52-0e2049d5de9f}" />

<!-- This is the guid used to group the menu commands together -->
<GuidSymbol name="guidDbContextPackageCmdSet" value="{c769a05d-8d51-4919-bfe6-5f35a0eaf2ba}">

<!-- Project Item Menu Entries -->

<IDSymbol name="cmdidDgmlBuild" value="0x0100" />
<IDSymbol name="cmdidDgmlNuget" value="0x0200" />
<IDSymbol name="cmdidT4Drop" value="0x0250" />
<IDSymbol name="cmdidEdmMenuAbout" value="0x0300" />
<IDSymbol name="cmdidSqlBuild" value="0x0400" />
<IDSymbol name="cmdidDebugViewBuild" value="0x0450" />
<IDSymbol name="cmdidEdmCompareMenuItemsGroup" value="0x0470" />
<IDSymbol name="cmdidEdmDatabaseMenuItemsGroup" value="0x0480" />
<IDSymbol name="cmdidEdmMigrationMenuItemsGroup" value="0x0490" />
<IDSymbol name="cmdidEdmMenu" value="0x0500" />
<IDSymbol name="cmdidEdmMenuGroup" value="0x0600" />
<IDSymbol name="cmdidEdmProjectMenuItemsGroup" value="0x0700" />
<IDSymbol name="cmdidEdmAboutMenuItemsGroup" value="0x0800" />
<IDSymbol name="cmdidEdmViewMenuItemsGroup" value="0x0900" />

<!-- Project Menu Entries -->
<IDSymbol name="cmdidReverseEngineerCodeFirst" value="0x0001" />
<IDSymbol name="cmdidEdmProjectMenuItemsGroup" value="0x0002" />
<IDSymbol name="cmdidEdmProjectMenu" value="0x0003" />
<IDSymbol name="cmdidEdmProjectMenuGroup" value="0x0004" />
<IDSymbol name="cmdidAbout" value="0x0006" />
<IDSymbol name="cmdidOptions" value="0x0010" />
<IDSymbol name="cmdidMigrationStatus" value="0x0007" />
<IDSymbol name="cmdidDbCompare" value="0x0008" />
<IDSymbol name="cmdidDbDgml" value="0x0009" />
</GuidSymbol>

<!-- This is the guid used to group the menu ReverseEngineer commands together -->
<GuidSymbol name="guidReverseEngineerMenu" value="{74bcf1bb-979c-408d-adcf-718c16e8f09e}">
<IDSymbol name="idReverseEngineerMenu" value="0x1000" />
<IDSymbol name="idReverseEngineerMenuGroup" value="0x1100" />
<IDSymbol name="cmdidReverseEngineerEdit" value="0x1101" />
<IDSymbol name="cmdidReverseEngineerRefresh" value="0x1102" />
</GuidSymbol>

<GuidSymbol name="guidVSPackageCommandProjectContextMenu" value="{069acb34-c12c-4e1c-ae69-1f9295046c84}" />

<GuidSymbol name="guidVSPackageCommandProjectContextMenuCmdSet" value="{9a55a2b4-3e29-4359-882b-fa5f51c09301}">
<IDSymbol name="MyGroupForCommands" value="0x1020" />
<!-- Warning!!: Keep the value in sync with the code in Command1.cs -->
<IDSymbol name="Command1Id" value="0x109" />
</GuidSymbol>

</Symbols>

</CommandTable>
15 changes: 15 additions & 0 deletions src/GUI/Shared/Handlers/ServerDgmlHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public async Task GenerateAsync()

var connectionString = info.DatabaseModel.ConnectionString;

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

if (info.DatabaseModel.DataConnection != null)
{
info.DatabaseModel.DataConnection.Open();
Expand All @@ -61,6 +66,7 @@ public async Task GenerateAsync()
{
var vsDataHelper = new VsDataHelper();
var databaseList = await vsDataHelper.GetDataConnectionsAsync(package);
var dacpacList = await SqlProjHelper.GetDacpacFilesInActiveSolutionAsync();

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

Expand All @@ -75,6 +81,15 @@ public async Task GenerateAsync()
}));
}

if (dacpacList != null && dacpacList.Any())
{
psd.PublishDefinitions(dacpacList.Select(m => new DatabaseConnectionModel
{
FilePath = m,
DatabaseType = DatabaseType.SQLServerDacpac,
}));
}

psd.PublishCodeGenerationMode(CodeGenerationMode.EFCore6, new List<CodeGenerationItem>());

var pickDataSourceResult = psd.ShowAndAwaitUserResponse(true);
Expand Down

0 comments on commit f8e2027

Please sign in to comment.