Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IsDirty generator when using a custom namespace #267

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Analyzer/CodeAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>GitInfo.CodeAnalysis</AssemblyName>
<TargetFramework>netstandard2.0</TargetFramework>
<PackFolder>analyzers/dotnet</PackFolder>
<PackFolder>analyzers/dotnet/roslyn4.0</PackFolder>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 11 additions & 6 deletions src/Analyzer/GitInfoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ class GitInfoGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.RegisterSourceOutput(
context.AdditionalTextsProvider
.Combine(context.AnalyzerConfigOptionsProvider)
.Combine(context.ParseOptionsProvider)
.Collect(),
(c, _) =>
var ns = context.AnalyzerConfigOptionsProvider
.Select((c, _) => c.GlobalOptions.TryGetValue("build_property.ThisAssemblyNamespace", out var ns)
&& !string.IsNullOrEmpty(ns) ? ns : null);

context.RegisterSourceOutput(ns,
(c, ns) =>
{
// Legacy codegen used for this scenario, emit nothing.
if (!string.IsNullOrEmpty(ns))
return;

c.AddSource("ThisAssembly.Git.IsDirty.g",
$$"""
//------------------------------------------------------------------------------
Expand All @@ -24,6 +28,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

partial class ThisAssembly
{
partial class Git
Expand Down
2 changes: 2 additions & 0 deletions src/GitInfo/buildMultiTargeting/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<!-- This makes sure we don't enforce SponsorLink transitively, but only when
consumers are directly referencing our package. -->
<SponsorablePackageId Include="GitInfo" />

<CompilerVisibleProperty Include="ThisAssemblyNamespace" />
</ItemGroup>

<Import Project="..\build\GitInfo.targets"/>
Expand Down
2 changes: 2 additions & 0 deletions src/GitInfo/buildTransitive/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<!-- This makes sure we don't enforce SponsorLink transitively, but only when
consumers are directly referencing our package. -->
<SponsorablePackageId Include="GitInfo" />

<CompilerVisibleProperty Include="ThisAssemblyNamespace" />
</ItemGroup>

<Import Project="..\build\GitInfo.targets"/>
Expand Down