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

守給你的承諾、 提交于 2019-12-07 17:02:43

问题


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.

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:


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



来源:https://stackoverflow.com/questions/44154869/single-file-generator-not-working-for-net-standard-projects-in-visual-studio-20

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!