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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TzData.Runtime.Linux.AutoInit" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TzData.Runtime.Linux.AutoInit" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TzData.Runtime.Linux.AutoInit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TzData.Runtime.Linux.AutoInit --version 1.0.1
                    
#r "nuget: TzData.Runtime.Linux.AutoInit, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TzData.Runtime.Linux.AutoInit@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TzData.Runtime.Linux.AutoInit&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TzData.Runtime.Linux.AutoInit&version=1.0.1
                    
Install as a Cake Tool

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:

  1. sets TZDIR to <app>/tzdata (unless it is already set);
  2. validates TzDataRuntimeAutoInitTimeZone against that data;
  3. overrides TZ with the build-time value and clears the TimeZoneInfo cache.

If validation fails, the environment TZ is left untouched. Leaving the property empty keeps the current environment behavior.

Opt-outs

  • TZDATA_DISABLE_DEFAULT_TZ=1 at runtime: ignore the build-time default and keep TZ.
  • <TzDataRuntimeAutoInit>false</TzDataRuntimeAutoInit>: do not inject the initializer at all.
  • <TzDataRuntimeAutoInitTimeZone></TzDataRuntimeAutoInitTimeZone>: no build-time default.

Guarantees and limits

  • Injected only when OutputType is Exe or WinExe. Libraries do not get the initializer, because a library may load after the app has already used TimeZoneInfo.
  • 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() returns false; nothing changes.
  • The build-time default also applies to child processes because TZ is 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, the TzDataRuntime.DefaultTimeZone assembly metadata;
  • content/TzDataAutoInit.cs — the module initializer that calls Configure() and applies the build-time default.

The package depends on TzData.Runtime.Linux so the API and the tzdata folder are available.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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