Buildtime
Allows meta-programming-like experience to reduce repetitive code.
app.Layers.AddBuildtime();
Configuration Targets
Buildtime layer provides IGeneratedAssemblyCollection,
IGeneratedFileCollection and GeneratedContext configuration targets.
IGeneratedAssemblyCollection
This target is provided in Generate phase. To configure it in a feature;
configurator.Buildtime.ConfigureGeneratedAssemblyCollection(assemblies =>
{
...
});
IGeneratedFileCollection
This target is provided in Compile phase. To configure it in a feature;
configurator.Buildtime.ConfigureGeneratedFileCollection(files =>
{
...
});
Phases
This layer introduces following Generate phases to the application it is added;
Generate: This phase creates aIGeneratedAssemblyCollectioninstance and places it in the application contextCompile: This phase compiles generated code during above phase, saves generated assemblies and files to entry assembly location withASPNETCORE_ENVIRONMENTsubfolder
To access to a generated assembly or file from a feature use below extension method;
configurator.Buildtime.UsingGeneratedContext(generatedContext => { // generated assembly var assembly = generatedContext.Assemblies[...]; // generated file helpers var path = generatedContext.Files[...]; var contentString = generatedContext.ReadFile(...); var data = generatedContext.ReadFileAsJson<...>(); });
Diagnostics
To have a better error output during generation we provide a diagnostics mechanism.
To define a known build error add an extension to DiagnosticCode;
extension(DiagnosticCode)
{
public static DiagnosticCode MyCustomCode => new(1);
}
And throw it from within conventions;
throw DiagnosticCode.MyCustomCode.Exception(
"Some custom message..."
);
This will print a single error line in build output during Generate task
instead of printing a full stack trace;
error C0001: Some custom message...
Reporting Custom Information
It is also possible to report any build output in error, warning and info
levels. To report a custom message simply call the corresponding report method
of Diagnostics.Current;
Diagnostics.Current.ReportError(myCode, myMessage);
Diagnostics.Current.ReportWarning(myCode, myMessage);
Diagnostics.Current.ReportInfo(myMessage);
To group together info messages that occur at different times you may use
group: optional parameter;
Diagnostics.Current.ReportInfo(myMessage, group: "my-group");