Single File Generator not working for .NET Standard Projects in Visual Studio 2017

Viewed 855

I've implemented a Single File Generator based off the template [1] (that compiles into an installable VSIX output, including the automatic registration of the 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.

example

All of the HasCustomTool.xml files have the same configuration, all of them have the 'Custom Tool' attribute specified.

When I look at the .csproj files, I can see that they are different. The (working) content of the DotNetCore.csproj file 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 DotNetStandard.csproj file has:

  <ItemGroup>
      <None Update="HasCustomTool.xml">
          <LastGenOutput>HasCustomTool.cs</LastGenOutput>
          <Generator>PtResxErrorTool</Generator>
      </None>
  </ItemGroup>

When you copy over the markup from DotNetCore.csproj to the DotNetStandard.csproj (by hand), you get the desired structure -- but the generator is never activated.

Has anybody successfully written a VSIX single file generator for .NET Standard projects? Any pointers on how to debug this problem?

[1] https://github.com/Microsoft/VSSDK-Extensibility-Samples/tree/master/Single_File_Generator

1 Answers

You need to add a new CodeGeneratorRegistration to your class.

"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"

in my case my class decl 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
{
}

The source info came from this thread

https://github.com/aspnet/Tooling/issues/394

Related