File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -6,14 +6,19 @@ class GitInfoGenerator : IIncrementalGenerator
66 public void Initialize ( IncrementalGeneratorInitializationContext context )
77 {
88 var ns = context . AnalyzerConfigOptionsProvider
9- . Select ( ( c , _ ) => c . GlobalOptions . TryGetValue ( "build_property.ThisAssemblyNamespace" , out var ns )
10- && ! string . IsNullOrEmpty ( ns ) ? ns : null ) ;
9+ . Select ( ( c , _ ) => new
10+ {
11+ Namespace = c . GlobalOptions . TryGetValue ( "build_property.ThisAssemblyNamespace" , out var ns )
12+ && ! string . IsNullOrEmpty ( ns ) ? ns : null ,
13+ IsDirty = c . GlobalOptions . TryGetValue ( "build_property.GitIsDirty" , out var dirty )
14+ && dirty == "1" ? true : false
15+ } ) ;
1116
1217 context . RegisterSourceOutput ( ns ,
13- ( c , ns ) =>
18+ ( c , state ) =>
1419 {
1520 // Legacy codegen used for this scenario, emit nothing.
16- if ( ! string . IsNullOrEmpty ( ns ) )
21+ if ( ! string . IsNullOrEmpty ( state . Namespace ) )
1722 return ;
1823
1924 c . AddSource ( "ThisAssembly.Git.IsDirty.g" ,
@@ -36,7 +41,7 @@ partial class Git
3641 /// <summary>
3742 /// Gets whether the current repository is dirty.
3843 /// </summary>
39- public static bool IsDirty => bool.TryParse(IsDirtyString, out var dirty) && dirty ;
44+ public const bool IsDirty = {{ ( state . IsDirty ? "true" : "false" ) }} ;
4045 }
4146 }
4247 """ ) ;
Original file line number Diff line number Diff line change 3434 </PropertyGroup >
3535
3636 <Target Name =" GitThisAssembly" DependsOnTargets =" $(GitThisAssemblyDependsOn)"
37- BeforeTargets =" PrepareConstants" Condition =" '$(GitThisAssembly)' == 'true'" >
37+ BeforeTargets =" PrepareConstants;GenerateMSBuildEditorConfigFileShouldRun " Condition =" '$(GitThisAssembly)' == 'true'" >
3838
3939 <ItemGroup >
40- <Constant Include =" IsDirtyString" Value =" $(IsDirtyString)" Root =" Git" />
40+ <CompilerVisibleProperty Include =" GitIsDirty" />
41+
42+ <Constant Include =" IsDirtyString" Value =" true" Root =" Git" Condition =" $(GitIsDirty) == '1'" />
43+ <Constant Include =" IsDirtyString" Value =" false" Root =" Git" Condition =" $(GitIsDirty) == '0'" />
44+
4145 <Constant Include =" RepositoryUrl" Value =" $(GitRepositoryUrl)" Root =" Git" />
4246
4347 <Constant Include =" Branch" Value =" $(GitBranch)" Root =" Git" />
You can’t perform that action at this time.
0 commit comments