65.9K
CodeProject 正在变化。 阅读更多。
Home

创建源代码生成器的样板指南 - 第五部分

starIconstarIconstarIconstarIconstarIcon

5.00/5 (3投票s)

2024年1月18日

MIT

1分钟阅读

viewsIcon

4773

一个包含 6 篇文章的系列,为您提供创建源代码生成器的样板指南。

目录

将源代码生成器打包成 NuGet 包

网上有很多关于如何创建 NuGet 包的视频和文章,因此我不会在这里详细描述,而是提供所需的基本信息以及一些必要的特定更改。

安装

将以下两个代码段添加到源代码生成器项目文件中。

<PropertyGroup>
  <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
  <IncludeBuildOutput>false</IncludeBuildOutput>
  <Version>1.0.0</Version>
  <Title>Test Data Mother Object Generator</Title>
  <Authors>David Elliott</Authors>
  <Company>Webbert Solutions, LLC</Company>
  <Description>A source code generator for creating mother objects for use in creating test code</Description>
</PropertyGroup>
<ItemGroup>
  <!-- Place the generator in the analyzer directory of the NuGet package -->
  <None Include="$(OutputPath)\$(AssemblyName).dll"
        Pack="true"
        PackagePath="analyzers/dotnet/cs"
        Visible="false" />
</ItemGroup>

第一个只是提供有关 NuGet 包的一般信息,除了 IncludeBuildOutput 之外,实际上并不重要。 这只是说明生成器 DLL 不应包含在您的项目输出中。

第二个提供有关该分析器信息以及在 NuGet 包中放置它的位置,以便在导入时可以对其进行适当处理。

创建 NuGet 包

您需要做的就是以发布模式构建生成器。

这将创建 bin -> Release -> RandomTestDataGenerator.1.0.0.nupkg

历史

  • 2024年1月18日:初始版本
© . All rights reserved.