Skip to content

Commit cf31318

Browse files
committed
Implemented Excel-DNA add-in project subtype. Restricted ribbon item templates to this subtype.
1 parent c7b9db4 commit cf31318

10 files changed

Lines changed: 86 additions & 1 deletion

File tree

ExcelDNAVSExtension/CSProjectTemplate/ProjectTemplate.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ProductVersion>8.0.30703</ProductVersion>
77
<SchemaVersion>2.0</SchemaVersion>
88
<ProjectGuid>$guid1$</ProjectGuid>
9+
<ProjectTypeGuids>{211e647a-3b33-4448-bc03-fac6d799aa09};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
910
<OutputType>Library</OutputType>
1011
<AppDesignerFolder>Properties</AppDesignerFolder>
1112
<RootNamespace>$safeprojectname$</RootNamespace>

ExcelDNAVSExtension/CSRibbonTemplate/CSRibbonTemplate.vstemplate

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<RequiredFrameworkVersion>4.5</RequiredFrameworkVersion>
1010
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
1111
<DefaultName>Ribbon.cs</DefaultName>
12+
<TemplateGroupID>Excel-DNA Add-in</TemplateGroupID>
13+
<ShowByDefault>false</ShowByDefault>
1214
</TemplateData>
1315
<TemplateContent>
1416
<References>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.VisualStudio.Shell.Flavor;
2+
3+
namespace ExcelDNAVSExtension
4+
{
5+
class AddinProject : FlavoredProjectBase
6+
{
7+
public AddinProject(Microsoft.VisualStudio.Shell.Package package, System.Guid addItemTemplates)
8+
{
9+
this.package = package;
10+
this.addItemTemplates = addItemTemplates;
11+
}
12+
13+
protected override void SetInnerProject(System.IntPtr innerIUnknown)
14+
{
15+
if (this.serviceProvider == null)
16+
this.serviceProvider = package;
17+
base.SetInnerProject(innerIUnknown);
18+
}
19+
20+
protected override System.Guid GetGuidProperty(uint itemId, int propId)
21+
{
22+
if (propId == (int)Microsoft.VisualStudio.Shell.Interop.__VSHPROPID2.VSHPROPID_AddItemTemplatesGuid)
23+
{
24+
return addItemTemplates;
25+
}
26+
return base.GetGuidProperty(itemId, propId);
27+
}
28+
29+
private Microsoft.VisualStudio.Shell.Package package;
30+
private System.Guid addItemTemplates;
31+
}
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace ExcelDNAVSExtension
2+
{
3+
class AddinProjectFactory : Microsoft.VisualStudio.Shell.Flavor.FlavoredProjectFactoryBase
4+
{
5+
public AddinProjectFactory(VSPackage package, System.Guid addItemTemplates)
6+
{
7+
this.package = package;
8+
this.addItemTemplates = addItemTemplates;
9+
}
10+
11+
protected override object PreCreateForOuter(System.IntPtr outerProjectIUnknown)
12+
{
13+
return new AddinProject(package, addItemTemplates);
14+
}
15+
16+
private Microsoft.VisualStudio.Shell.Package package;
17+
private System.Guid addItemTemplates;
18+
}
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ExcelDNAVSExtension
2+
{
3+
[System.Runtime.InteropServices.Guid("211e647a-3b33-4448-bc03-fac6d799aa09")]
4+
class CSAddinProjectFactory : AddinProjectFactory
5+
{
6+
public CSAddinProjectFactory(VSPackage package) : base(package, typeof(CSAddinProjectFactory).GUID)
7+
{
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ExcelDNAVSExtension
2+
{
3+
[System.Runtime.InteropServices.Guid("7c62086f-14b6-45f0-a11b-31698fd43e99")]
4+
class VBAddinProjectFactory : AddinProjectFactory
5+
{
6+
public VBAddinProjectFactory(VSPackage package) : base(package, typeof(VBAddinProjectFactory).GUID)
7+
{
8+
}
9+
}
10+
}

ExcelDNAVSExtension/ExcelDNAVSExtension/ExcelDNAVSExtension.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@
5353
<NoWarn>VSTHRD010,VSSDK006</NoWarn>
5454
</PropertyGroup>
5555
<ItemGroup>
56+
<Compile Include="AddinProject\AddinProject.cs" />
5657
<Compile Include="Commands.cs" />
58+
<Compile Include="AddinProject\CSAddinProjectFactory.cs" />
5759
<Compile Include="ExceptionHandler.cs" />
5860
<Compile Include="ProjectCreationOptions.cs" />
61+
<Compile Include="AddinProject\AddinProjectFactory.cs" />
5962
<Compile Include="Properties\AssemblyInfo.cs" />
6063
<Compile Include="TemplateWizard.cs" />
6164
<Compile Include="TemplateWizardDialog.xaml.cs">
6265
<DependentUpon>TemplateWizardDialog.xaml</DependentUpon>
6366
</Compile>
67+
<Compile Include="AddinProject\VBAddinProjectFactory.cs" />
6468
<Compile Include="VSExceptionSettings.cs" />
6569
<Compile Include="VSPackage.cs" />
6670
<Compile Include="XmlSchemas.cs" />
@@ -156,6 +160,7 @@
156160
<SubType>Designer</SubType>
157161
</Page>
158162
</ItemGroup>
163+
<ItemGroup />
159164
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
160165
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
161166
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

ExcelDNAVSExtension/ExcelDNAVSExtension/VSPackage.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ namespace ExcelDNAVSExtension
1717
{
1818
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
1919
[Guid(VSPackage.PackageGuidString)]
20-
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
20+
[ProvideProjectFactory(typeof(CSAddinProjectFactory), "Excel-DNA Add-in CSharp", null, null, null, null, TemplateGroupIDsVsTemplate = "Excel-DNA Add-in", LanguageVsTemplate = "CSharp")]
21+
[ProvideProjectFactory(typeof(VBAddinProjectFactory), "Excel-DNA Add-in VisualBasic", null, null, null, null, TemplateGroupIDsVsTemplate = "Excel-DNA Add-in", LanguageVsTemplate = "VisualBasic")]
2122
[ProvideMenuResource("Menus.ctmenu", 1)]
2223
public sealed class VSPackage : AsyncPackage
2324
{
@@ -34,6 +35,8 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
3435
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
3536
try
3637
{
38+
RegisterProjectFactory((IVsProjectFactory)new CSAddinProjectFactory(this));
39+
RegisterProjectFactory((IVsProjectFactory)new VBAddinProjectFactory(this));
3740
commands = new Commands(this);
3841
}
3942
catch (System.Exception e)

ExcelDNAVSExtension/VBProjectTemplate/ProjectTemplate.vbproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<SchemaVersion>
99
</SchemaVersion>
1010
<ProjectGuid>{$guid2$}</ProjectGuid>
11+
<ProjectTypeGuids>{7c62086f-14b6-45f0-a11b-31698fd43e99};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
1112
<OutputType>Library</OutputType>
1213
<RootNamespace>$safeprojectname$</RootNamespace>
1314
<AssemblyName>$safeprojectname$</AssemblyName>

ExcelDNAVSExtension/VBRibbonTemplate/VBRibbonTemplate.vstemplate

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<ProjectType>VisualBasic</ProjectType>
1111
<RequiredFrameworkVersion>4.5</RequiredFrameworkVersion>
1212
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
13+
<TemplateGroupID>Excel-DNA Add-in</TemplateGroupID>
14+
<ShowByDefault>false</ShowByDefault>
1315
</TemplateData>
1416
<TemplateContent>
1517
<References>

0 commit comments

Comments
 (0)