Skip to content

Commit

Permalink
Package the SG into the runtime package
Browse files Browse the repository at this point in the history
The SG can be disabled by the consumer project by settings the following
MSBuild property:

    <DisableCSnakesRuntimeSourceGenerator>true</DisableCSnakesRuntimeSourceGenerator>
  • Loading branch information
RussKie committed Sep 18, 2024
1 parent 9ed59f3 commit 737ca07
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CSnakes.SourceGeneration" Version="1.*-*" />
<PackageReference Include="CSnakes.Runtime" Version="1.*-*" />
</ItemGroup>

Expand Down
11 changes: 6 additions & 5 deletions src/CSnakes.Runtime/CSnakes.Runtime.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>CSnakes.Runtime</PackageId>
<Title>CSnakes Runtime</Title>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>$(EnableLocalPackaging)</GeneratePackageOnBuild>

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<!-- Tensor<T> and related APIs in System.Numerics.Tensors are experimental in .NET 9 -->
Expand All @@ -23,4 +18,10 @@
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<ItemGroup>
<!-- Reference the source generator purely for packaging purposes -->
<ProjectReference Include="..\CSnakes.SourceGeneration\CSnakes.SourceGeneration.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<Import Project="Packaging.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project>
<Target Name="_CSnakes_Runtime_GatherAnalyzers">

<ItemGroup>
<_CSnakes_Runtime_Analyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'CSnakes.Runtime'" />
</ItemGroup>
</Target>

<Target Name="_CSnakes_Runtime_RemoveAnalyzers"
Condition="'$(DisableCSnakesRuntimeSourceGenerator)' == 'true'"
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
DependsOnTargets="_CSnakes_Runtime_GatherAnalyzers">

<!-- Remove all our analyzers -->
<ItemGroup>
<Analyzer Remove="@(_CSnakes_Runtime_Analyzer)" />
</ItemGroup>
</Target>
</Project>
33 changes: 33 additions & 0 deletions src/CSnakes.Runtime/Packaging.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project>
<PropertyGroup>
<PackageId>CSnakes.Runtime</PackageId>
<Title>CSnakes Runtime</Title>
<IsPackable>true</IsPackable>

<!-- warning NU5128: Add lib or ref assemblies for the netstandard2.0 target framework -->
<NoWarn>$(NoWarn);NU5128</NoWarn>

<DevelopmentDependency>true</DevelopmentDependency>
<GeneratePackageOnBuild>$(EnableLocalPackaging)</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<None Include="NuGet\buildTransitive\**\*" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath="buildTransitive\%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<Target Name="_PackSourceGeneratorOutputs" BeforeTargets="_GetPackageFiles">
<!-- Find out the source generator and its dependencies locations -->
<MSBuild Projects="@(ProjectReference)"
Targets="GetTargetPath"
BuildInParallel="true"
Properties="TargetFramework=netstandard2.0"
Condition="$([System.String]::Copy('%(Identity)').Contains('CSnakes.SourceGeneration'))">
<Output TaskParameter="TargetOutputs" ItemName="DependentAssemblies" />
</MSBuild>

<!-- ...and pack the dependencies -->
<ItemGroup>
<None Include="@(DependentAssemblies)" Pack="true" PackagePath="analyzers/dotnet/cs" />
</ItemGroup>
</Target>
</Project>
3 changes: 0 additions & 3 deletions src/CSnakes.SourceGeneration/CSnakes.SourceGeneration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<NoWarn>$(NoWarn);RS1035</NoWarn>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,6 +27,4 @@
<TargetPathWithTargetPlatformMoniker Include="$(PKGSuperpower)\lib\netstandard2.0\Superpower.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>

<Import Project="Packaging.targets" />
</Project>
24 changes: 0 additions & 24 deletions src/CSnakes.SourceGeneration/Packaging.targets

This file was deleted.

0 comments on commit 737ca07

Please sign in to comment.