Skip to content

Add netstandard2.0 target framework to Microsoft.ApplicationInsights#3142

Merged
rajkumar-rangaraj merged 2 commits intomainfrom
rajrang/netstd
Mar 13, 2026
Merged

Add netstandard2.0 target framework to Microsoft.ApplicationInsights#3142
rajkumar-rangaraj merged 2 commits intomainfrom
rajrang/netstd

Conversation

@rajkumar-rangaraj
Copy link
Copy Markdown
Member

Fix Issue #3130

Customers with shared libraries targeting netstandard2.0 cannot reference the Microsoft.ApplicationInsights NuGet package after the 3.0.0 release removed netstandard2.0. This PR adds netstandard2.0 to the core SDK to restore support for these library authors.

At runtime, the host application (targeting net8.0/net9.0/net10.0) resolves the concrete TFM build of the SDK — the netstandard2.0 build is only used at compile time by the shared library. All NuGet dependencies (Azure.Monitor.OpenTelemetry.Exporter 1.6.0, OpenTelemetry 1.15.0, System.Diagnostics.DiagnosticSource 10.0.2) ship netstandard2.0 builds, so no version bifurcation is needed.

No source code changes were required — all existing #if conditional compilation already has netstandard2.0-compatible fallback paths.

Changes

  • BASE/src/Microsoft.ApplicationInsights/Microsoft.ApplicationInsights.csproj — Added netstandard2.0 to <TargetFrameworks>, scoped System.Net.Http reference to net462 only, excluded EventRegister for netstandard2.0
  • Directory.Build.props — Added netstandard2.0 to IsNetStandard20 condition
  • CHANGELOG.md — Added entry under Unreleased
  • BreakingChanges.md — Corrected stale NLog target framework documentation

Checklist

  • I ran Unit Tests locally.
  • CHANGELOG.md updated with one line description of the fix, and a link to the original issue if available.

For significant contributions please make sure you have completed the following items:

  • Design discussion issue #
  • Changes in public surface reviewed

The PR will trigger build, unit tests, and functional tests automatically. Please follow these instructions to build and test locally.

Notes for authors:

  • FxCop and other analyzers will fail the build. To see these errors yourself, compile localy using the Release configuration.

Copilot AI review requested due to automatic review settings March 13, 2026 21:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reintroduces a netstandard2.0 build target for the Microsoft.ApplicationInsights (BASE) package and updates repository-wide build properties and documentation to reflect the targeting change.

Changes:

  • Add netstandard2.0 to Microsoft.ApplicationInsights multi-targeting and adjust related conditional references.
  • Update build props to recognize netstandard2.0 as part of the IsNetStandard20 condition.
  • Document the change in CHANGELOG.md and update target framework breaking-changes notes.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
Directory.Build.props Updates target-framework classification to include netstandard2.0 in IsNetStandard20.
CHANGELOG.md Adds an Unreleased entry describing the added netstandard2.0 target.
BreakingChanges.md Updates the documented 3.x target frameworks for the NLogTarget section.
BASE/src/Microsoft.ApplicationInsights/Microsoft.ApplicationInsights.csproj Adds netstandard2.0 to TargetFrameworks and updates conditional references accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Updated the changelog to include a link for the addition of the `netstandard2.0` target framework in the `Microsoft.ApplicationInsights` package.
@rajkumar-rangaraj rajkumar-rangaraj merged commit 843b612 into main Mar 13, 2026
18 checks passed
@rajkumar-rangaraj rajkumar-rangaraj deleted the rajrang/netstd branch March 13, 2026 23:05
rajkumar-rangaraj added a commit that referenced this pull request Mar 31, 2026
- Replace IServiceProvider service locator with direct constructor injection
  of TelemetryConfiguration and IConfiguration in
  DisableTelemetryInitializerHostedService (both are singletons).
- Restore accidentally dropped CHANGELOG entries for #3153 and #3142.
harsimar pushed a commit that referenced this pull request Mar 31, 2026
* Fix DisableTelemetry not disabling metrics export

OTEL_SDK_DISABLED was set in IConfiguration too late (during AzureMonitorExporterOptions
callback) after the OTel MeterProvider had already been constructed and checked the flag.

Fix: Register a DisableTelemetryInitializerHostedService at position 0 in the service
collection so it runs before OpenTelemetry's TelemetryHostedService, setting
OTEL_SDK_DISABLED in IConfiguration before providers are built.

Consolidated the registration in the shared AddTelemetryConfigAndClient method so both
AspNetCore and WorkerService packages benefit from the fix.

* Update CHANGELOG with PR #3156

* Address Copilot review: direct injection + restore CHANGELOG entries

- Replace IServiceProvider service locator with direct constructor injection
  of TelemetryConfiguration and IConfiguration in
  DisableTelemetryInitializerHostedService (both are singletons).
- Restore accidentally dropped CHANGELOG entries for #3153 and #3142.

* Fix DisableTelemetry: set OTEL_SDK_DISABLED in TelemetryConfiguration factory

The hosted service approach did not work because MeterProvider is resolved
during the DI configuration phase (via UseAzureMonitorExporter -> options
resolution), before any hosted service runs.

Move OTEL_SDK_DISABLED assignment into the TelemetryConfiguration singleton
factory so it is set immediately after applying Configure callbacks.
Since TelemetryConfiguration is always resolved before MeterProvider, this
guarantees the flag is visible when the OTel SDK checks it.

Remove DisableTelemetryInitializerHostedService (no longer needed).
This was referenced Apr 2, 2026
This was referenced Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants