Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.
Open
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
5 changes: 5 additions & 0 deletions AutoT4/AutoT4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Resource Include="Resources\GenerateT4.png" />
<Content Include="Resources\Package.ico" />
<VSCTCompile Include="AutoT4Package.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
<SubType>Designer</SubType>
</VSCTCompile>
</ItemGroup>
<PropertyGroup>
<UseCodebase>true</UseCodebase>
Expand Down
19 changes: 19 additions & 0 deletions AutoT4/AutoT4Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using EnvDTE;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System;

namespace BennorMcCarthy.AutoT4
{
Expand All @@ -13,8 +15,12 @@ namespace BennorMcCarthy.AutoT4
[Guid(GuidList.guidAutoT4PkgString)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string)]
[ProvideOptionPage(typeof(Options), Options.CategoryName, Options.PageName, 1000, 1001, false)]
[ProvideMenuResource("Menus.ctmenu", 1)]
public sealed class AutoT4Package : Package
{
private const int CommandId = 0x0100;
private static readonly Guid CommandSet = new Guid("92c31ba2-5827-4779-b3ff-cf0fed43e50a");

private DTE _dte;
private BuildEvents _buildEvents;
private ObjectExtenders _objectExtenders;
Expand All @@ -38,6 +44,11 @@ protected override void Initialize()
RegisterExtenderProvider(VSConstants.CATID.VBFileProperties_string);

RegisterEvents();

var commandService = (IMenuCommandService)GetService(typeof(IMenuCommandService));
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(this.RunTemplates, menuCommandID);
commandService.AddCommand(menuItem);
}

private void RegisterEvents()
Expand Down Expand Up @@ -78,6 +89,14 @@ private void RunTemplates(vsBuildScope scope, RunOnBuild buildEvent, bool runIfD
.ForEach(item => item.RunTemplate());
}

private void RunTemplates(object sender, EventArgs e)
{
_dte.GetProjectsWithinBuildScope(vsBuildScope.vsBuildScopeSolution)
.FindT4ProjectItems()
.ToList()
.ForEach(item => item.RunTemplate());
}

protected override int QueryClose(out bool canClose)
{
int result = base.QueryClose(out canClose);
Expand Down
90 changes: 90 additions & 0 deletions AutoT4/AutoT4Package.vsct
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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 actual layout and type of the commands.
It is divided in different sections (e.g. command definition, command
placement, ...), with each defining a specific set of properties.
See the comment before each section for more details about how to
use it. -->

<!-- The VSCT compiler (the tool that translates this file into the binary
format that VisualStudio will consume) has the ability to run a preprocessor
on the vsct file; this preprocessor is (usually) the C++ preprocessor, so
it is possible to define includes and macros with the same syntax used
in C++ files. Using this ability of the compiler here, we include some files
defining some of the constants that we will use inside the file. -->

<!--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"/>

<!--The Commands section is where 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="guidAutoT4Package">
<!-- Inside this section we have different sub-sections: one for the menus, another
for the menu groups, one for the buttons (the actual commands), one for the combos
and the last one for the bitmaps used. Each element is identified by a command id that
is a unique pair of guid and numeric identifier; the guid part of the identifier is usually
called "command set" and is used to group different command inside a logically related
group; your package should define its own command set in order to avoid collisions
with command ids defined by other packages. -->

<!-- In this section you can define new menu groups. A menu group is a container for
other menus or buttons (commands); from a visual point of view you can see the
group as the part of a menu contained between two lines. The parent of a group
must be a menu. -->
<Groups>
<Group guid="guidAutoT4PackageCmdSet" id="AutoT4Group" priority="0x0600">
<!--<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>-->
<Parent guid="guidSHLMainMenu" id="IDM_VS_TOOL_PROJWIN"/>
</Group>
</Groups>

<!--Buttons section. -->
<!--This section defines the elements the user can interact with, like a menu command or a button
or combo box in a toolbar. -->
<Buttons>
<!--To define a menu group you have to specify its ID, the parent menu and its display priority.
The command is visible and enabled by default. If you need to change the visibility, status, etc, you can use
the CommandFlag node.
You can add more than one CommandFlag node e.g.:
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
If you do not want an image next to your command, remove the Icon node /> -->
<Button guid="guidAutoT4PackageCmdSet" id="GenerateT4Id" priority="0x0100" type="Button">
<Parent guid="guidAutoT4PackageCmdSet" id="AutoT4Group" />
<Icon guid="guidImages" id="T4" />
<Strings>
<ButtonText>Invoke GenerateT4</ButtonText>
</Strings>
</Button>
</Buttons>

<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
<Bitmaps>
<!-- The bitmap id is defined in a way that is a little bit different from the others:
the declaration starts with a guid for the bitmap strip, then there is the resource id of the
bitmap strip containing the bitmaps and then there are the numeric ids of the elements used
inside a button definition. An important aspect of this declaration is that the element id
must be the actual index (1-based) of the bitmap inside the bitmap strip. -->
<Bitmap guid="guidImages" href="Resources\GenerateT4.png" usedList="T4"/>
</Bitmaps>
</Commands>

<Symbols>
<!-- This is the package guid. -->
<GuidSymbol name="guidAutoT4Package" value="{3fe81b73-39c9-4e39-8742-8e3fc01493bd}" />

<!-- This is the guid used to group the menu commands together -->
<GuidSymbol name="guidAutoT4PackageCmdSet" value="{92c31ba2-5827-4779-b3ff-cf0fed43e50a}">
<IDSymbol name="AutoT4Group" value="0x1020" />
<IDSymbol name="GenerateT4Id" value="0x0100" />
</GuidSymbol>

<GuidSymbol name="guidImages" value="{13e443b3-8e03-4189-9ea6-86be51c6a790}" >
<IDSymbol name="T4" value="1" />
</GuidSymbol>
</Symbols>
</CommandTable>
Binary file added AutoT4/Resources/GenerateT4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.