Skip to content

Commit 0613e23

Browse files
authored
Merge pull request #69 from jeromelaban/dev/jela/source-include
feat: Restore source inclusion as an option
2 parents e23ba6f + 86e8e53 commit 0613e23

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The CodeGenHelpers is built to help people to write C# Code generators. If you l
66
|----|:---:|
77
| [AvantiPoint.CodeGenHelpers](https://www.nuget.org/packages/AvantiPoint.CodeGenHelpers/) | ![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/AvantiPoint.CodeGenHelpers?style=plastic) |
88

9-
> Note: Version 2.0 will no longer ship as source code linked into your project and will now ship as a pre-compiled library.
9+
> Note: Version 2.0 will no longer ship as source code linked into your project by default and will now ship as a pre-compiled library. To include the helpers as source, set `<CodeGenHelpersMode>source</CodeGenHelpersMode>` in your project.
1010
1111
## Why Use the Helpers?
1212

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "6.0.400"
3+
"version": "6.0.400","rollForward": "latestMajor"
44
}
55
}

src/CodeGenHelpers/AvantiPoint.CodeGenHelpers.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PackageTags>source generators;codegen;avantipoint;roslyn</PackageTags>
1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1111
<LangVersion>latest</LangVersion>
12-
12+
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_AddGeneratorsToOutput</TargetsForTfmSpecificContentInPackage>
1313
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1414
<NoWarn>$(NoWarn);NU5128;</NoWarn>
1515
</PropertyGroup>
@@ -18,5 +18,15 @@
1818
<InternalsVisibleTo Include="CodeGenHelpers.Tests" />
1919
<None Update="ReadMe.txt" Pack="true" PackagePath="" />
2020
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" />
21+
<None Include="AvantiPoint.CodeGenHelpers.props" Pack="true" PackagePath="build" />
22+
<None Include="AvantiPoint.CodeGenHelpers.targets" Pack="true" PackagePath="build" />
2123
</ItemGroup>
24+
25+
<Target Name="_AddGeneratorsToOutput">
26+
<ItemGroup>
27+
<TfmSpecificPackageFile Include="*.cs" PackagePath="build/content" />
28+
<TfmSpecificPackageFile Include="Internals\*.cs" PackagePath="build/content/Internals" />
29+
<TfmSpecificPackageFile Include="Extensions\*.cs" PackagePath="build/content/Extensions" />
30+
</ItemGroup>
31+
</Target>
2232
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Project>
3+
4+
<PropertyGroup>
5+
<CodeGenHelpersMode Condition=" '$(CodeGenHelpersMode)' == '' ">Assembly</CodeGenHelpersMode>
6+
</PropertyGroup>
7+
8+
<ItemGroup Condition=" '$(CodeGenHelpersMode)' == 'Source' ">
9+
<Compile Include="$(MSBuildThisFileDirectory)content\**\*.cs" LinkBase="CodeGenHelpers" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Project>
3+
4+
<Target Name="RemoveAssemblyReferenceOnSourceMode"
5+
BeforeTargets="FindReferenceAssembliesForReferences"
6+
Condition=" '$(CodeGenHelpersMode)' == 'Source' ">
7+
8+
<ItemGroup>
9+
<_CodeGenHelpersReferenceToRemove
10+
Include="@(ReferencePath)"
11+
Condition=" '%(ReferencePath.NuGetPackageId)' == 'AvantiPoint.CodeGenHelpers' " />
12+
13+
<!-- Remove all references -->
14+
<ReferencePath Remove="@(_CodeGenHelpersReferenceToRemove)" />
15+
<ReferenceCopyLocalPaths Remove="@(_CodeGenHelpersReferenceToRemove)" />
16+
17+
<!-- Clear items -->
18+
<_CodeGenHelpersReferenceToRemove Remove="@(_CodeGenHelpersReferenceToRemove)" />
19+
</ItemGroup>
20+
21+
</Target>
22+
23+
</Project>

src/CodeGenHelpers/ReadMe.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
Thanks for downloading the AvantiPoint CodeGenHelpers. This helper library will help you more easily write Source Generators with a pattern that allows you to pass in strings, some System Type's or Roslyn Type Symbols. The generated code can be added to the builder in any order and will output a nicely formatted source file.
22

3+
The CodeGenHelpers come in two flavors, set using `CodeGenHelpersMode`:
4+
- `Assembly`, in order to be used as a normal assembly
5+
- `Source`, where the helpers are linked as source files to eliminate issues with assembly references.
6+
37
Please consider becomming a sponsor at https://github.com/sponsors/dansiegel

0 commit comments

Comments
 (0)