Jos*_*osh 7 c# nuget sourcegenerators
我创建了一个 C# 源生成器,并想将其发布到 Nuget。
但我遇到了警告/错误,例如:
Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below: - Add lib or ref assemblies for the netstandard2.0 target frameworkAn instance of analyzer Cosmogenesis.Generator.CosmosGenerator cannot be created from [..]\Cosmogenesis.Generator.dll : Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified..(或 Version=2.0.0.0 取决于我正在尝试的内容)有一些资源解释了如何操作,但似乎没有一个在我的具体场景中起作用,即:
Cosmogenesis.Core
Cosmogenesis.Generator(刚刚在 Nuget 上发布Cosmogenesis)
理想情况下,我希望能够从 Nuget 安装,它会自动与生成器一起Cosmogenesis引入。Cosmogenesis.Core
使用 NuGet 包中的功能<-- 解释了我的场景(不同的 .net 标准要求除外)。....还有一个附带问题:如果解释如何使其自动引用,为什么它有代码来检查程序集是否被引用?...
反正...
Cosmogenesis.Core发布没有任何问题。
Cosmogenesis.Generator也使用此.csproj发布
有用。但是,消费者需要参考这两个包。我希望他们只需要引用一个包。
当我添加<IncludeBuildOutput>false</IncludeBuildOutput>(按照上面的教程)时,在构建时我收到此警告:Some target frameworks declared...[参见上文]。如果我忽略它并无论如何发布它,当我在项目中使用该包并构建它时,生成器不会运行,并且我收到此警告:An instance of analyzer...[参见上文]。
当我添加时<PackageReference Include="Cosmogenesis.Core" Version="0.0.1" />(按照上面的教程),我收到错误。生成器是 .NET Standard 2.0,而 .Core 包是 2.1。错误是:error NU1202: Package Cosmogenesis.Core 0.0.1 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package Cosmogenesis.Core 0.0.1 supports: netstandard2.1 (.NETStandard,Version=v2.1)。可以理解。
当我将生成器项目设置为 2.1 以修复不匹配问题时,构建时不会出现警告,但消费者再次收到错误An instance of analyzer...。 C# 源生成器 - 编写代码来编写代码 - David Wengier说它们必须是 .net 标准 2.0。
这是我的第一个 nuget 包。还有我的第一个源生成器。有人可以建议吗?
编辑:我 75% 确信roslyn github 问题的解决方案可以解决我的问题。