TzData.Runtime.Linux.AutoInit
1.0.1
dotnet add package TzData.Runtime.Linux.AutoInit --version 1.0.1
NuGet\Install-Package TzData.Runtime.Linux.AutoInit -Version 1.0.1
<PackageReference Include="TzData.Runtime.Linux.AutoInit" Version="1.0.1" />
<PackageVersion Include="TzData.Runtime.Linux.AutoInit" Version="1.0.1" />
<PackageReference Include="TzData.Runtime.Linux.AutoInit" />
paket add TzData.Runtime.Linux.AutoInit --version 1.0.1
#r "nuget: TzData.Runtime.Linux.AutoInit, 1.0.1"
#:package TzData.Runtime.Linux.AutoInit@1.0.1
#addin nuget:?package=TzData.Runtime.Linux.AutoInit&version=1.0.1
#tool nuget:?package=TzData.Runtime.Linux.AutoInit&version=1.0.1
TzData.Runtime.Linux.AutoInit
Opt-in companion package for TzData.Runtime.Linux. It injects a module initializer
into executable projects so TzDataRuntime.Configure() runs before Main — no startup code
needed. Linux only; macOS/Windows are no-ops.
<ItemGroup>
<PackageReference Include="TzData.Runtime.Linux.AutoInit" Version="1.0.1" />
</ItemGroup>
Default local time zone (optional)
<PropertyGroup>
<TzDataRuntimeAutoInitTimeZone>Asia/Shanghai</TzDataRuntimeAutoInitTimeZone>
</PropertyGroup>
Precedence: build-time default > TZ environment variable > /etc/localtime > UTC.
The value is baked into the app assembly as metadata. At startup the initializer:
- sets
TZDIRto<app>/tzdata(unless it is already set); - validates
TzDataRuntimeAutoInitTimeZoneagainst that data; - overrides
TZwith the build-time value and clears theTimeZoneInfocache.
If validation fails, the environment TZ is left untouched. Leaving the property empty keeps the
current environment behavior.
Opt-outs
TZDATA_DISABLE_DEFAULT_TZ=1at runtime: ignore the build-time default and keepTZ.<TzDataRuntimeAutoInit>false</TzDataRuntimeAutoInit>: do not inject the initializer at all.<TzDataRuntimeAutoInitTimeZone></TzDataRuntimeAutoInitTimeZone>: no build-time default.
Guarantees and limits
- Injected only when
OutputTypeisExeorWinExe. Libraries do not get the initializer, because a library may load after the app has already usedTimeZoneInfo. - Runs once, synchronously, before
Main, for the app assembly. - Exceptions are swallowed: a missing data folder or invalid zone never prevents the app from starting.
- Non-Linux platforms:
Configure()returnsfalse; nothing changes. - The build-time default also applies to child processes because
TZis a process environment variable.
How it works
The package ships:
buildTransitive/TzData.Runtime.Linux.AutoInit.targets— adds the injected source for executable projects and, when configured, theTzDataRuntime.DefaultTimeZoneassembly metadata;content/TzDataAutoInit.cs— the module initializer that callsConfigure()and applies the build-time default.
The package depends on TzData.Runtime.Linux so the API and the tzdata folder are available.
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- TzData.Runtime.Linux (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 81 | 11/21/2026 |