Open sandboxFocusImprove this doc

Well-Known Environment Variables

PostSharp reads two kinds of environment variables:

  • Environment variables named like an MSBuild property. MSBuild imports every environment variable as a property, so you can set any property of Well-Known MSBuild Properties with an environment variable of the same name. For instance, the PostSharpLicense environment variable sets the PostSharpLicense property. For details, see Configuring Projects Using MSBuild.
  • Environment variables that PostSharp reads directly. They have no equivalent MSBuild property. Most of them are machine-wide settings, typically defined on a build server. This article lists them.
Note

On .NET Framework, PostSharp can run in a background process named the pipe server (see the PostSharpUsePipeServer property in Well-Known MSBuild Properties). The pipe server keeps the environment variables that it was started with. When you change a variable that PostSharp reads at build time, end the pipe server process, or disable the pipe server with PostSharpUsePipeServer=False, before the next build.

Note

The environment variables that PostSharp reads but that this article does not list are implementation details. They may change without notice.

Throttling Concurrent Builds

These variables limit the resources that PostSharp uses when many projects build at the same time, for instance on a build server or in a container with a memory limit. They are not set by default.

Variable Name Description
POSTSHARP_MAX_PARALLELISM A positive integer. When this variable is set:
- The PostSharp MSBuild task acquires a slot from a machine-wide semaphore before it starts PostSharp. The number of slots is the value of the variable. This throttling is supported on Windows only.
- The number of PostSharp processes, and of concurrent builds in the pipe server, is limited to the value of the variable instead of the number of processors.
- PostSharp builds the type index of a target framework in one process at a time. This limits the memory used by parallel builds.
POSTSHARP_CONCURRENCY_TIMEOUT_MINUTES A positive integer. The time, in minutes, that the PostSharp MSBuild task waits for a slot of the POSTSHARP_MAX_PARALLELISM semaphore. The default value is 15. When no slot becomes available within this time, the task reports an error and the build fails. This situation happens when a build starts another build and the inner build waits for a slot that the outer build holds.
POSTSHARP_REQUIRED_MEMORY A positive integer. The amount of physical memory, in megabytes, that must be available before the PostSharp MSBuild task starts PostSharp. When less memory is available, the task waits and reports a warning. After 10 seconds, it requests the shutdown of the idle .NET build servers (dotnet build-server shutdown). After 5 minutes, it starts PostSharp with the available memory. This variable is supported on Windows and Linux only.

Retrying Locked Files

When another process locks a file that PostSharp reads or writes, for instance an antivirus or another build, PostSharp retries the operation until the file is unlocked or a timeout expires. The following variables configure this behavior of the PostSharp compiler. The FileLock trace category writes the details of the retries (see the PostSharpTrace property in Well-Known MSBuild Properties).

Variable Name Description
POSTSHARP_FILE_LOCK_TIMEOUT A positive integer. The time, in milliseconds, after which PostSharp reports an error for a file that stays locked. The default value is 10000 (10 seconds). The first attempt always runs, even with a very short timeout. An empty or invalid value means the default value.
POSTSHARP_FILE_LOCK_WARNING A non-negative integer. The time, in milliseconds, after which PostSharp reports a warning for a file that stays locked. The default value is 5000 (5 seconds). The value 0 reports a warning at the first retry. A value that is equal to or greater than POSTSHARP_FILE_LOCK_TIMEOUT disables the warning, so that only the error is reported. An operation that succeeds at the first attempt never causes a warning.
Note

The PostSharpLockedFileTimeout and PostSharpLockedFileWarningTimeout MSBuild properties do not have the same effect. They configure the copy of files that the PostSharp MSBuild targets do before and after the execution of PostSharp. See Well-Known MSBuild Properties.

Diagnostics

Variable Name Description
HAS_JIT_DEBUGGER True or False, or 1 or 0. Specifies whether a just-in-time debugger is installed on the machine. When PostSharpAttachDebugger is set to True and a just-in-time debugger is installed, PostSharp calls System.Diagnostics.Debugger.Launch(). Otherwise, PostSharp writes its process identifier to the build log and waits until you attach a debugger. By default, PostSharp detects the debugger automatically, and assumes that no debugger is installed in a container. For details, see Debugging Build-Time Logic.
PostSharpAttachDebuggerOnException Any non-empty value. PostSharp calls System.Diagnostics.Debugger.Launch() when it reports an unhandled exception, so that you can inspect the exception in a debugger.
POSTSHARPSERVER_DEBUG True to launch a debugger when the pipe server process starts. The MSBuild task then waits for the pipe server without timeout.

Hosting on .NET

These variables affect the PostSharp process that runs on .NET (.NET Core), that is, when the current project does not target .NET Framework.

Variable Name Description
POSTSHARPHOST_DISABLE_CACHE True to generate the runtimeconfig.json and deps.json files of the PostSharp process at every build. By default, PostSharp generates them again only when the project.assets.json file of the project changes.
POSTSHARPHOST_DISABLE_NATIVE_FRAMEWORK_OVERRIDE True to disable the override of the native framework. When the target framework of the project has a higher version or platform version than the runtime installed on the machine, for instance net8.0-windows10.0.22621.0, PostSharp runs with the higher version by default, and reports a warning. With this variable, PostSharp runs with the installed version.
POSTSHARPHOST_DISABLE_NATIVE_FRAMEWORK_OVERRIDE_WARNING True to remove the warning that PostSharp reports when it overrides the native framework.

Third-Party Environment Variables

PostSharp also reads the following environment variables, which are defined by other products.

Variable Name Description
NUGET_PACKAGES The location of the global NuGet package folder. PostSharp searches the packages of the project in this folder.
XDG_DATA_HOME, XDG_CONFIG_HOME On Linux and macOS, the base directories of the machine-wide and user NuGet configuration files.
PROCESSOR_ARCHITECTURE, PROCESSOR_ARCHITEW6432 On Windows, used to detect whether MSBuild runs as a 32-bit process on a 64-bit operating system.

See Also

Other Resources

Well-Known MSBuild Properties
Configuring Projects Using MSBuild
Debugging Build-Time Logic
Deploying License Keys