我做了一个C#9源代码生成器,你可以找到它here https://github.com/HamedFathi/MockableStaticGenerator
当我在另一个解决方案中使用整个项目并将其作为项目引用时,它可以工作,但是当我将其与当前配置一起上传到 Nuget 时(here https://www.nuget.org/packages/MockableStaticGenerator/) 这是行不通的。
如何正确配置 C# 9 源生成器以作为 Nuget 包工作?我的项目出了什么问题?
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.0.2</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>dotnet</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<GenerateRepositoryUrlAttribute>true</GenerateRepositoryUrlAttribute>
<PackBuildOutput>true</PackBuildOutput>
<PackageId>MockableStaticGenerator</PackageId>
<PackOnBuild>true</PackOnBuild>
<PackFolder>analyzers\cs</PackFolder>
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
如果解压 nuget 包,您将看到该包存储在 lib 目录中。它必须存储在分析器目录中。
一种方法是将以下内容添加到您的 csproj 中:
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
如果你是多目标,它应该是:
<ItemGroup>
<None Include="$(OutputPath)\netstandard2.0\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
这将包括您的项目作为库和分析器。
要将其用作分析器,请添加以下内容:
<PropertyGroup>
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)