单个文件生成器不适用于 Visual Studio 2017 年的 .NET 标准项目
Single File Generator not working for .NET Standard Projects in Visual Studio 2017
我已经实现了一个基于模板 [1] 的单一文件生成器(编译成可安装的 VSIX 输出,包括组件的自动注册)和:
- 它适用于 VS 2015 和 VS2017 中的经典 .NET 项目;
- 它适用于 VS2017 中的 .NET Core 项目;
- 但不适用于 VS2017 中的 .NET Standard 项目。
所有 HasCustomTool.xml
文件都具有相同的配置,它们都指定了 'Custom Tool' 属性。
当我查看 .csproj
文件时,我发现它们是不同的。 DotNetCore.csproj
文件的(工作)内容是:
<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>
而 DotNetStandard.csproj
文件有:
<ItemGroup>
<None Update="HasCustomTool.xml">
<LastGenOutput>HasCustomTool.cs</LastGenOutput>
<Generator>PtResxErrorTool</Generator>
</None>
</ItemGroup>
当您将标记从 DotNetCore.csproj
复制到 DotNetStandard.csproj
(手动)时,您会得到所需的结构——但生成器永远不会被激活。
有人成功地为 .NET Standard 项目编写了 VSIX 单文件生成器吗?关于如何调试此问题的任何指示?
[1] https://github.com/Microsoft/VSSDK-Extensibility-Samples/tree/master/Single_File_Generator
您需要向 class 添加一个新的 CodeGeneratorRegistration。
"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"
在我的例子中,我的 class 声明看起来像
[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
{
}
源信息来自此线程
我已经实现了一个基于模板 [1] 的单一文件生成器(编译成可安装的 VSIX 输出,包括组件的自动注册)和:
- 它适用于 VS 2015 和 VS2017 中的经典 .NET 项目;
- 它适用于 VS2017 中的 .NET Core 项目;
- 但不适用于 VS2017 中的 .NET Standard 项目。
所有 HasCustomTool.xml
文件都具有相同的配置,它们都指定了 'Custom Tool' 属性。
当我查看 .csproj
文件时,我发现它们是不同的。 DotNetCore.csproj
文件的(工作)内容是:
<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>
而 DotNetStandard.csproj
文件有:
<ItemGroup>
<None Update="HasCustomTool.xml">
<LastGenOutput>HasCustomTool.cs</LastGenOutput>
<Generator>PtResxErrorTool</Generator>
</None>
</ItemGroup>
当您将标记从 DotNetCore.csproj
复制到 DotNetStandard.csproj
(手动)时,您会得到所需的结构——但生成器永远不会被激活。
有人成功地为 .NET Standard 项目编写了 VSIX 单文件生成器吗?关于如何调试此问题的任何指示?
[1] https://github.com/Microsoft/VSSDK-Extensibility-Samples/tree/master/Single_File_Generator
您需要向 class 添加一个新的 CodeGeneratorRegistration。
"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"
在我的例子中,我的 class 声明看起来像
[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
{
}
源信息来自此线程