AzureFunctions.DisabledWhen
1.0.0-prerelease
dotnet add package AzureFunctions.DisabledWhen --version 1.0.0-prerelease
NuGet\Install-Package AzureFunctions.DisabledWhen -Version 1.0.0-prerelease
<PackageReference Include="AzureFunctions.DisabledWhen" Version="1.0.0-prerelease" />
<PackageVersion Include="AzureFunctions.DisabledWhen" Version="1.0.0-prerelease" />
<PackageReference Include="AzureFunctions.DisabledWhen" />
paket add AzureFunctions.DisabledWhen --version 1.0.0-prerelease
#r "nuget: AzureFunctions.DisabledWhen, 1.0.0-prerelease"
#:package AzureFunctions.DisabledWhen@1.0.0-prerelease
#addin nuget:?package=AzureFunctions.DisabledWhen&version=1.0.0-prerelease&prerelease
#tool nuget:?package=AzureFunctions.DisabledWhen&version=1.0.0-prerelease&prerelease
AzureFunctions.DisabledWhen
Conditionally disable Azure Functions based on configuration values using attributes.
Packages
| Package | Description |
|---|---|
AzureFunctions.DisabledWhen |
Reflection-based implementation |
AzureFunctions.DisabledWhen.SourceGenerator |
Source-generated implementation |
Installation
Reflection-based (simple setup)
dotnet add package AzureFunctions.DisabledWhen
See sample/SampleFunctionApp for a working example.
Source-generated (AOT-compatible)
dotnet add package AzureFunctions.DisabledWhen
dotnet add package AzureFunctions.DisabledWhen.SourceGenerator
Add this to your .csproj to enable interceptors:
<PropertyGroup>
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);AzureFunctions.DisabledWhen</InterceptorsPreviewNamespaces>
</PropertyGroup>
See sample/SampleFunctionApp.SourceGenerated for a working example.
Note: The source generator only discovers functions in the same assembly where
UseDisabledWhen()is called. If your functions are spread across multiple assemblies, use the reflection-based package instead.
Usage
1. Register the metadata provider
In your Program.cs, call UseDisabledWhen() on the host builder after ConfigureFunctionsWebApplication():
using AzureFunctions.DisabledWhen;
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.UseDisabledWhen() // Must be called after ConfigureFunctionsWebApplication
.Build();
host.Run();
Important:
UseDisabledWhen()must be called afterConfigureFunctionsWebApplication()(orConfigureFunctionsWorkerDefaults()) to ensure the default function metadata provider is registered first.
2. Apply attributes to functions
using AzureFunctions.DisabledWhen;
public class MyFunctions
{
[Function("ScheduledCleanup")]
[DisabledWhenLocal]
public static void ScheduledCleanup(
[TimerTrigger("0 */5 * * * *", RunOnStartup = true)] TimerInfo timer)
{
}
[Function("ProcessOrderQueue")]
[DisabledWhenNullOrEmpty("ServiceBusConnection")]
public static void ProcessOrderQueue(
[ServiceBusTrigger("orders", Connection = "ServiceBusConnection")] string message)
{
}
[Function("GdprDataExport")]
[DisabledWhen("EnvironmentOptions:RegionAbbreviation", "US", StringComparison.OrdinalIgnoreCase)]
[DisabledWhen("EnvironmentOptions:RegionAbbreviation", "CA", StringComparison.OrdinalIgnoreCase)]
[DisabledWhen("EnvironmentOptions:RegionAbbreviation", "AU", StringComparison.OrdinalIgnoreCase)]
public static IActionResult GdprDataExport(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "gdpr/export/{userId}")] HttpRequest req,
string userId)
{
}
}
Attributes
DisabledWhenAttribute
Disables a function when a configuration key matches a specific value.
[DisabledWhen("ConfigKey", "ConfigValue")]
[DisabledWhen("ConfigKey", "ConfigValue", StringComparison.OrdinalIgnoreCase)]
DisabledWhenLocalAttribute
Disables a function when AZURE_FUNCTIONS_ENVIRONMENT equals Development.
[DisabledWhenLocal]
Read more about AZURE_FUNCTIONS_ENVIRONMENT.
DisabledWhenNullOrEmptyAttribute
Disables a function when a configuration key is missing, null, or empty.
[DisabledWhenNullOrEmpty("RequiredConfigKey")]
How It Works
The library provides a custom IFunctionMetadataProvider that evaluates attribute conditions at startup and excludes disabled functions from registration. The approach is inspired from this github issue.
When using both packages, the SourceGenerator intercepts calls to UseDisabledWhen() and replaces the reflection-based implementation with a compile-time generated version that is AOT-compatible.
Since filtering happens at startup:
- Configuration changes require a restart to take effect
- Disabled functions don't appear in the Azure Portal
- Disabled functions are logged as warnings
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Azure.Functions.Worker.Core (>= 2.51.0)
-
net8.0
- Microsoft.Azure.Functions.Worker.Core (>= 2.51.0)
-
net9.0
- Microsoft.Azure.Functions.Worker.Core (>= 2.51.0)
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.0-prerelease | 44 | 1/21/2026 |