You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve source generation both for Roslyn-based and for BT-based SG #1732
We should use IIncrementalSourceGenerator for CsWin32 not only because it's recommended but because NativeMethods.txt is expected to have relatively a large number of entries. Re-generating the whole source every time NativeMethods.txt or .json degrades the VS performance on large projects.
Plus, the BuildTask one has Inputs and Outputs @ GenerateCsWin32Code but once called, it generates the whole source.
Roslyn-based SG Design
[Generator]publicsealedclassSourceGenerator:IIncrementalGenerator{publicvoidInitialize(IncrementalGeneratorInitializationContextcontext){varoptions=context.AdditionalTextsProvider.Where(static file =>Path.GetFileName(file.Path).EndsWith("NativeMethods.json",StringComparison.OrdinalIgnoreCase)).Collect().Select(static(files,ct)=>ParseOptions(files,ct));varnativeMethods=context.AdditionalTextsProvider.Where(static file =>Path.GetFileName(file.Path).EndsWith("NativeMethods.txt",StringComparison.OrdinalIgnoreCase)).Select(static(file,ct)=>ReadNativeMethods(file,ct)).Collect();varbuildProps=context.AnalyzerConfigOptionsProvider.Select(static(provider,ct)=>ReadBuildProperties(provider.GlobalOptions));varinputs=context.CompilationProvider.Combine(context.ParseOptionsProvider).Combine(options).Combine(nativeMethods).Combine(buildProps);context.RegisterSourceOutput(inputs,static(spc,input)=>{// existing Execute body, but driven from immutable input modelsGenerate(spc,input);});}}
Activity