3

我创建了一个 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 framework
  • An 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
    • .NET 标准 2.1
    • 不依赖于生成器,但生成的源代码依赖于它
  • Cosmogenesis.Generator(刚刚发布在 Nuget 上Cosmogenesis
    • .NET 标准 2.0
    • 这是源生成器

理想情况下,我希望能够Cosmogenesis从 Nuget 安装,它会自动Cosmogenesis.Core与生成器一起引入。

使用 NuGet 包中的功能<--解释了我的方案(不同的 .net 标准要求除外)。....作为一个附带问题:如果它解释如何使其被自动引用,为什么它有代码来检查是否引用了一个程序集?

反正...

这是Github 上的 Cosmogenesis

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# Source Generators - 编写代码来编写代码 - David Wengier说它们必须是 .net 标准 2.0。

这是我的第一个 nuget 包。还有我的第一个源生成器。任何人都可以建议吗?

编辑:我 75% 确定这个 roslyn github 问题的解决方案可以解决我的问题。

4

0 回答 0