Single file generator does not work for standard .NET projects in Visual Studio 2017
I have implemented a single file generator based on the template [1] (which compiles into installable VSIX output, including auto-registering components) and:
- It works for classic .NET projects in VS 2015 and VS2017;
- It works for .NET Core projects in VS2017;
- But doesn't work for .NET Standard projects in VS2017.
All files HasCustomTool.xml
have the same configuration, all of which have a Custom Tool attribute.
When I look at the files .csproj
, I see that they are different. The (working) content of the file DotNetCore.csproj
is:
<ItemGroup>
<Compile Update="HasCustomTool.cs">
<DependentUpon>HasCustomTool.xml</DependentUpon>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="HasCustomTool.xml">
<LastGenOutput>HasCustomTool.cs</LastGenOutput>
<Generator>PtResxErrorTool</Generator>
</None>
</ItemGroup>
Whereas the file DotNetStandard.csproj
has:
<ItemGroup>
<None Update="HasCustomTool.xml">
<LastGenOutput>HasCustomTool.cs</LastGenOutput>
<Generator>PtResxErrorTool</Generator>
</None>
</ItemGroup>
When you copy the markup from DotNetCore.csproj
to DotNetStandard.csproj
(manually) you get the structure you want, but the generator is never activated.
Has anyone successfully written a VSIX single file generator for .NET Standard projects? Any pointers to debug this issue?
[1] https://github.com/Microsoft/VSSDK-Extensibility-Samples/tree/master/Single_File_Generator
source to share
You need to add a new group CodeGeneratorRegistration to your class.
"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"
in my case my decl class looked like
[ComVisible(true)]
[Guid(GuidList.GuidI18NReactivetring)]
[ProvideObject(typeof(I18NReactive))]
[CodeGeneratorRegistration(typeof(I18NReactive), "I18N.Reactive", vsContextGuids.vsContextGuidVCSProject, GeneratesDesignTimeSource = true)]
[CodeGeneratorRegistration(typeof(I18NReactive), "I18N.Reactive", "{9A19103F-16F7-4668-BE54-9A1E7A4F7556}", GeneratesDesignTimeSource = true)]
public class I18NReactive : IVsSingleFileGenerator, IObjectWithSite
{
}
Source information obtained from this stream
source to share