-
Notifications
You must be signed in to change notification settings - Fork 226
Settings.AdditionalFileHeaderText
Put your own lines verbatim at the top and bottom of every generated file.
AdditionalFileHeaderText |
AdditionalFileFooterText |
|
| Type | List<string> |
List<string> |
| Default | Empty | Empty |
| Position | After // <auto-generated>, before the using lines |
After the namespace closes, before // </auto-generated>
|
In Database.tt? |
Yes | Yes |
Each list entry becomes one line, written exactly as you give it. Nothing is escaped, prefixed or indented -
if you want a comment, write the // yourself.
The header list lands above the using block, which is the only place in a generated file where a
file-scoped directive can go.
Settings.AdditionalFileHeaderText = new List<string>
{
"// Owned by the Platform team",
"// Do not edit by hand"
};// <auto-generated>
// Owned by the Platform team
// Do not edit by hand
using Microsoft.Data.SqlClient;Analyser and linter suppressions that need to be at the top of the file:
Settings.AdditionalFileHeaderText = new List<string>
{
"#pragma warning disable CS8618 // Non-nullable property must contain a non-null value",
"// <autogenerated />"
};A #nullable directive finer-grained than
Settings.AllowNullStrings gives you:
Settings.AdditionalFileHeaderText = new List<string> { "#nullable disable" };Licence or provenance headers your organisation requires on every source file.
Coverage exclusions in the footer, for tools that read a trailing marker.
Verbatim means verbatim. A line without // or # is a compiler error, and the error appears in the
generated file where the line number means nothing to you.
The header goes before the using lines, so using statements of your own work here - but
Settings.AdditionalNamespaces is the right way to add one, because it is
sorted in with the rest and deduplicated.
#pragma warning disable written here is never restored, like the one
Settings.UsePragma writes. That is fine for generated code and wrong anywhere else.
They apply to every generated file, so with
Settings.GenerateSeparateFiles on, a five-line header appears sixty times.
The footer is outside the namespace. It is written after the closing brace, so it cannot contain code that belongs to a type.
-
Settings.AdditionalNamespaces - the right way to add a
using - Settings.UsePragma | Settings.UseResharper - the built-in header lines
-
Settings.AllowNullStrings - which writes
#nullable enablefor you - Settings Reference
- Settings A-Z - every setting, with a page each
- Common Settings Types Explained
- Settings Callbacks
- Settings runtime values and helpers
- Filtering
- Full Control Over the Generated Code
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Data Annotations
- Spatial Types
- HierarchyId
- RowVersion and TimeStamp columns
- Lazy Loading
- Stored proc result sets
- Custom File-Based Templates
- Extra entities via partial classes
- INotifyPropertyChanged
- Syntax colour for T4