Skip to content

Commit 60d0098

Browse files
Added SingleFileGenerator sample
1 parent f938d3a commit 60d0098

12 files changed

+345
-2
lines changed

Samples.sln

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31320.298
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31821.396
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InsertGuid", "InsertGuid\InsertGuid.csproj", "{96B4BD5D-E91C-4DAF-BD35-EA70FC7A5D21}"
77
EndProject
@@ -15,24 +15,48 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Options", "Options\Options.
1515
EndProject
1616
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolWindow", "ToolWindow\ToolWindow.csproj", "{ED5C3050-C684-4D15-AA9E-5350B9273D36}"
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleFileGenerator", "SingleFileGenerator\SingleFileGenerator.csproj", "{7126F617-9F1D-4238-A5D4-5224F45049E9}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|Any CPU = Debug|Any CPU
23+
Debug|x86 = Debug|x86
2124
Release|Any CPU = Release|Any CPU
25+
Release|x86 = Release|x86
2226
EndGlobalSection
2327
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2428
{96B4BD5D-E91C-4DAF-BD35-EA70FC7A5D21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2529
{96B4BD5D-E91C-4DAF-BD35-EA70FC7A5D21}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{96B4BD5D-E91C-4DAF-BD35-EA70FC7A5D21}.Debug|x86.ActiveCfg = Debug|x86
31+
{96B4BD5D-E91C-4DAF-BD35-EA70FC7A5D21}.Debug|x86.Build.0 = Debug|x86
2632
{96B4BD5D-E91C-4DAF-BD35-EA70FC7A5D21}.Release|Any CPU.ActiveCfg = Release|Any CPU
2733
{96B4BD5D-E91C-4DAF-BD35-EA70FC7A5D21}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{96B4BD5D-E91C-4DAF-BD35-EA70FC7A5D21}.Release|x86.ActiveCfg = Release|x86
35+
{96B4BD5D-E91C-4DAF-BD35-EA70FC7A5D21}.Release|x86.Build.0 = Release|x86
2836
{80FEE53F-F74A-4B5B-8604-179FE3CA4F61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2937
{80FEE53F-F74A-4B5B-8604-179FE3CA4F61}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{80FEE53F-F74A-4B5B-8604-179FE3CA4F61}.Debug|x86.ActiveCfg = Debug|x86
39+
{80FEE53F-F74A-4B5B-8604-179FE3CA4F61}.Debug|x86.Build.0 = Debug|x86
3040
{80FEE53F-F74A-4B5B-8604-179FE3CA4F61}.Release|Any CPU.ActiveCfg = Release|Any CPU
3141
{80FEE53F-F74A-4B5B-8604-179FE3CA4F61}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{80FEE53F-F74A-4B5B-8604-179FE3CA4F61}.Release|x86.ActiveCfg = Release|x86
43+
{80FEE53F-F74A-4B5B-8604-179FE3CA4F61}.Release|x86.Build.0 = Release|x86
3244
{ED5C3050-C684-4D15-AA9E-5350B9273D36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3345
{ED5C3050-C684-4D15-AA9E-5350B9273D36}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{ED5C3050-C684-4D15-AA9E-5350B9273D36}.Debug|x86.ActiveCfg = Debug|x86
47+
{ED5C3050-C684-4D15-AA9E-5350B9273D36}.Debug|x86.Build.0 = Debug|x86
3448
{ED5C3050-C684-4D15-AA9E-5350B9273D36}.Release|Any CPU.ActiveCfg = Release|Any CPU
3549
{ED5C3050-C684-4D15-AA9E-5350B9273D36}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{ED5C3050-C684-4D15-AA9E-5350B9273D36}.Release|x86.ActiveCfg = Release|x86
51+
{ED5C3050-C684-4D15-AA9E-5350B9273D36}.Release|x86.Build.0 = Release|x86
52+
{7126F617-9F1D-4238-A5D4-5224F45049E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53+
{7126F617-9F1D-4238-A5D4-5224F45049E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
54+
{7126F617-9F1D-4238-A5D4-5224F45049E9}.Debug|x86.ActiveCfg = Debug|x86
55+
{7126F617-9F1D-4238-A5D4-5224F45049E9}.Debug|x86.Build.0 = Debug|x86
56+
{7126F617-9F1D-4238-A5D4-5224F45049E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
57+
{7126F617-9F1D-4238-A5D4-5224F45049E9}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{7126F617-9F1D-4238-A5D4-5224F45049E9}.Release|x86.ActiveCfg = Release|x86
59+
{7126F617-9F1D-4238-A5D4-5224F45049E9}.Release|x86.Build.0 = Release|x86
3660
EndGlobalSection
3761
GlobalSection(SolutionProperties) = preSolution
3862
HideSolutionNode = FALSE
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using SingleFileGenerator.Generators;
2+
3+
namespace SingleFileGenerator
4+
{
5+
[Command(PackageIds.MyCommand)]
6+
internal sealed class MyCommand : BaseCommand<MyCommand>
7+
{
8+
protected override Task InitializeCompletedAsync()
9+
{
10+
Command.Supported = false;
11+
return base.InitializeCompletedAsync();
12+
}
13+
14+
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
15+
{
16+
var file = await VS.Solutions.GetActiveItemAsync() as PhysicalFile;
17+
18+
await file.TrySetAttributeAsync("custom tool", SassToCss.Name);
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Text;
2+
using Microsoft.VisualStudio.TextTemplating.VSHost;
3+
using NUglify;
4+
using SharpScss;
5+
6+
namespace SingleFileGenerator.Generators
7+
{
8+
public class SassToCss : BaseCodeGeneratorWithSite
9+
{
10+
public const string Name = nameof(SassToCss);
11+
12+
public const string Description = "Transpiles Sass/Scss files to CSS";
13+
14+
public override string GetDefaultExtension() => ".css";
15+
16+
protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
17+
{
18+
ScssResult results = Scss.ConvertToCss(inputFileContent);
19+
UglifyResult minified = Uglify.Css(results.Css);
20+
21+
return Encoding.UTF8.GetBytes(minified.Code);
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using SingleFileGenerator;
2+
3+
using System.Reflection;
4+
using System.Runtime.InteropServices;
5+
6+
[assembly: AssemblyTitle(Vsix.Name)]
7+
[assembly: AssemblyDescription(Vsix.Description)]
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany(Vsix.Author)]
10+
[assembly: AssemblyProduct(Vsix.Name)]
11+
[assembly: AssemblyCopyright(Vsix.Author)]
12+
[assembly: AssemblyTrademark("")]
13+
[assembly: AssemblyCulture("")]
14+
15+
[assembly: ComVisible(false)]
16+
17+
[assembly: AssemblyVersion(Vsix.Version)]
18+
[assembly: AssemblyFileVersion(Vsix.Version)]
19+
20+
namespace System.Runtime.CompilerServices
21+
{
22+
public class IsExternalInit { }
23+
}
266 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
5+
<LangVersion>latest</LangVersion>
6+
</PropertyGroup>
7+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
8+
<PropertyGroup>
9+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
10+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
11+
<SchemaVersion>2.0</SchemaVersion>
12+
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
13+
<ProjectGuid>{7126F617-9F1D-4238-A5D4-5224F45049E9}</ProjectGuid>
14+
<OutputType>Library</OutputType>
15+
<AppDesignerFolder>Properties</AppDesignerFolder>
16+
<RootNamespace>SingleFileGenerator</RootNamespace>
17+
<AssemblyName>SingleFileGenerator</AssemblyName>
18+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
19+
<GeneratePkgDefFile>true</GeneratePkgDefFile>
20+
<UseCodebase>true</UseCodebase>
21+
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
22+
<IncludeDebugSymbolsInVSIXContainer>true</IncludeDebugSymbolsInVSIXContainer>
23+
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
24+
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
25+
<CopyOutputSymbolsToOutputDirectory>true</CopyOutputSymbolsToOutputDirectory>
26+
<StartAction>Program</StartAction>
27+
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
28+
<StartArguments>/rootsuffix Exp</StartArguments>
29+
</PropertyGroup>
30+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
31+
<DebugSymbols>true</DebugSymbols>
32+
<DebugType>full</DebugType>
33+
<Optimize>false</Optimize>
34+
<OutputPath>bin\Debug\</OutputPath>
35+
<DefineConstants>DEBUG;TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
</PropertyGroup>
39+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
40+
<DebugType>pdbonly</DebugType>
41+
<Optimize>true</Optimize>
42+
<OutputPath>bin\Release\</OutputPath>
43+
<DefineConstants>TRACE</DefineConstants>
44+
<ErrorReport>prompt</ErrorReport>
45+
<WarningLevel>4</WarningLevel>
46+
</PropertyGroup>
47+
<ItemGroup>
48+
<Compile Include="Generators\SassToCss.cs" />
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
<Compile Include="Commands\MyCommand.cs" />
51+
<Compile Include="SingleFileGeneratorPackage.cs" />
52+
<Compile Include="source.extension.cs">
53+
<AutoGen>True</AutoGen>
54+
<DesignTime>True</DesignTime>
55+
<DependentUpon>source.extension.vsixmanifest</DependentUpon>
56+
</Compile>
57+
<Compile Include="VSCommandTable.cs">
58+
<AutoGen>True</AutoGen>
59+
<DesignTime>True</DesignTime>
60+
<DependentUpon>VSCommandTable.vsct</DependentUpon>
61+
</Compile>
62+
</ItemGroup>
63+
<ItemGroup>
64+
<None Include="source.extension.vsixmanifest">
65+
<SubType>Designer</SubType>
66+
<Generator>VsixManifestGenerator</Generator>
67+
<LastGenOutput>source.extension.cs</LastGenOutput>
68+
</None>
69+
<Content Include="libsass.dll">
70+
<IncludeInVSIX>true</IncludeInVSIX>
71+
</Content>
72+
<Content Include="Resources\Icon.png">
73+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
74+
<IncludeInVSIX>true</IncludeInVSIX>
75+
</Content>
76+
</ItemGroup>
77+
<ItemGroup>
78+
<VSCTCompile Include="VSCommandTable.vsct">
79+
<ResourceName>Menus.ctmenu</ResourceName>
80+
<Generator>VsctGenerator</Generator>
81+
<LastGenOutput>VSCommandTable.cs</LastGenOutput>
82+
</VSCTCompile>
83+
</ItemGroup>
84+
<ItemGroup>
85+
<Reference Include="System" />
86+
<Reference Include="System.Design" />
87+
</ItemGroup>
88+
<ItemGroup>
89+
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
90+
<PackageReference Include="Community.VisualStudio.Toolkit" Version="17.0.76.303" ExcludeAssets="Runtime" />
91+
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.0.5232" />
92+
<PackageReference Include="NUglify">
93+
<Version>1.16.1</Version>
94+
</PackageReference>
95+
<PackageReference Include="SharpScss" PrivateAssets="Compile">
96+
<Version>2.0.0</Version>
97+
</PackageReference>
98+
</ItemGroup>
99+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
100+
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
101+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
102+
Other similar extension points exist, see Microsoft.Common.targets.
103+
<Target Name="BeforeBuild">
104+
</Target>
105+
<Target Name="AfterBuild">
106+
</Target>
107+
-->
108+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
global using System;
2+
global using Community.VisualStudio.Toolkit;
3+
global using Microsoft.VisualStudio.Shell;
4+
global using Task = System.Threading.Tasks.Task;
5+
using System.Runtime.InteropServices;
6+
using System.Threading;
7+
using Microsoft.VisualStudio.TextTemplating.VSHost;
8+
using SingleFileGenerator.Generators;
9+
10+
namespace SingleFileGenerator
11+
{
12+
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
13+
[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
14+
[ProvideMenuResource("Menus.ctmenu", 1)]
15+
[Guid(PackageGuids.SingleFileGeneratorString)]
16+
[ProvideCodeGenerator(typeof(SassToCss), SassToCss.Name, SassToCss.Description, true, RegisterCodeBase = true)]
17+
[ProvideCodeGeneratorExtension(SassToCss.Name, ".scss")]
18+
[ProvideCodeGeneratorExtension(SassToCss.Name, ".sass")]
19+
[ProvideUIContextRule(PackageGuids.CommandVisisiblityString,
20+
name: "Sass files",
21+
expression: "Sass",
22+
termNames: new[] { "Sass" },
23+
termValues: new[] { "HierSingleSelectionName:.s(a|c)ss$" })]
24+
public sealed class SingleFileGeneratorPackage : ToolkitPackage
25+
{
26+
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
27+
{
28+
await this.RegisterCommandsAsync();
29+
}
30+
}
31+
}

SingleFileGenerator/VSCommandTable.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// ------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This file was generated by VSIX Synchronizer
4+
// </auto-generated>
5+
// ------------------------------------------------------------------------------
6+
namespace SingleFileGenerator
7+
{
8+
using System;
9+
10+
/// <summary>
11+
/// Helper class that exposes all GUIDs used across VS Package.
12+
/// </summary>
13+
internal sealed partial class PackageGuids
14+
{
15+
public const string CommandVisisiblityString = "525190a4-9c61-4aa5-8319-7c5fb75dae59";
16+
public static Guid CommandVisisiblity = new Guid(CommandVisisiblityString);
17+
18+
public const string SingleFileGeneratorString = "525190a4-9c61-4aa5-8319-7c5fb75dae58";
19+
public static Guid SingleFileGenerator = new Guid(SingleFileGeneratorString);
20+
}
21+
/// <summary>
22+
/// Helper class that encapsulates all CommandIDs uses across VS Package.
23+
/// </summary>
24+
internal sealed partial class PackageIds
25+
{
26+
public const int MyMenuGroup = 0x0001;
27+
public const int MyCommand = 0x0100;
28+
}
29+
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
4+
<Extern href="stdidcmd.h"/>
5+
<Extern href="vsshlids.h"/>
6+
<Include href="KnownImageIds.vsct"/>
7+
<Include href="VSGlobals.vsct"/>
8+
9+
<Commands package="SingleFileGenerator">
10+
<Groups>
11+
<Group guid="SingleFileGenerator" id="MyMenuGroup" priority="0x0600">
12+
<Parent guid="VSMainMenu" id="ItemNode.OpenGroup"/>
13+
</Group>
14+
</Groups>
15+
16+
<!--This section defines the elements the user can interact with, like a menu command or a button
17+
or combo box in a toolbar. -->
18+
<Buttons>
19+
<Button guid="SingleFileGenerator" id="MyCommand" priority="0x0100" type="Button">
20+
<Parent guid="VSMainMenu" id="ItemNode.OpenGroup"/>
21+
<Icon guid="ImageCatalogGuid" id="SASSStyleSheet" />
22+
<CommandFlag>DynamicVisibility</CommandFlag>
23+
<CommandFlag>IconIsMoniker</CommandFlag>
24+
<Strings>
25+
<ButtonText>Transpile Scss to CSS</ButtonText>
26+
<LocCanonicalName>.SingleFileGenerator.MyCommand</LocCanonicalName>
27+
</Strings>
28+
</Button>
29+
</Buttons>
30+
</Commands>
31+
32+
<VisibilityConstraints>
33+
<VisibilityItem guid="SingleFileGenerator" id="MyCommand" context="CommandVisisiblity" />
34+
</VisibilityConstraints>
35+
36+
<Symbols>
37+
<GuidSymbol name="CommandVisisiblity" value="{525190a4-9c61-4aa5-8319-7c5fb75dae59}" />
38+
39+
<GuidSymbol name="SingleFileGenerator" value="{525190a4-9c61-4aa5-8319-7c5fb75dae58}">
40+
<IDSymbol name="MyMenuGroup" value="0x0001" />
41+
<IDSymbol name="MyCommand" value="0x0100" />
42+
</GuidSymbol>
43+
</Symbols>
44+
</CommandTable>

SingleFileGenerator/libsass.dll

1.9 MB
Binary file not shown.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This file was generated by VSIX Synchronizer
4+
// </auto-generated>
5+
// ------------------------------------------------------------------------------
6+
namespace SingleFileGenerator
7+
{
8+
internal sealed partial class Vsix
9+
{
10+
public const string Id = "SingleFileGenerator.514e283c-668d-4360-94c9-b2d7ed2ff33c";
11+
public const string Name = "Single File Generator";
12+
public const string Description = @"Empty VSIX Project.";
13+
public const string Language = "en-US";
14+
public const string Version = "1.0";
15+
public const string Author = "Mads Kristensen";
16+
public const string Tags = "";
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
3+
<Metadata>
4+
<Identity Id="SingleFileGenerator.514e283c-668d-4360-94c9-b2d7ed2ff33c" Version="1.0" Language="en-US" Publisher="Mads Kristensen" />
5+
<DisplayName>Single File Generator</DisplayName>
6+
<Description xml:space="preserve">Empty VSIX Project.</Description>
7+
<Icon>Resources\Icon.png</Icon>
8+
<PreviewImage>Resources\Icon.png</PreviewImage>
9+
</Metadata>
10+
<Installation>
11+
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
12+
<ProductArchitecture>amd64</ProductArchitecture>
13+
</InstallationTarget>
14+
</Installation>
15+
<Prerequisites>
16+
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,)" DisplayName="Visual Studio core editor" />
17+
</Prerequisites>
18+
<Assets>
19+
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
20+
</Assets>
21+
</PackageManifest>

0 commit comments

Comments
 (0)