Skip to content

Conversation

Copy link

Copilot AI commented Nov 1, 2025

Issue #279: Implicit framework defines like NET6_0 and NET6_0_OR_GREATER were not being defined for .NET 6+ projects, breaking conditional compilation and breaking top-level statements.

Root Cause

DisableImplicitFrameworkDefines was left uncommented (but inactive), creating ambiguity. When not explicitly set to false, the Microsoft.NET.Sdk's implicit define logic may be disabled, preventing defines like NET6_0, NET6_0_OR_GREATER, and platform-specific constants from being added.

Changes

  • Platforms.targets (line 45): Explicitly set DisableImplicitFrameworkDefines=false to ensure SDK implicit defines are always generated
  • Test project: Added Tests/ImplicitFrameworkDefines/ to verify defines are present using #error directives that fail compilation if missing

Example

With this fix, projects can now use:

#if NET6_0_OR_GREATER
    // Modern .NET 6+ code
#endif

#if NET6_0_WINDOWS
    // Windows-specific .NET 6 code
#endif

And top-level statements work correctly in multi-targeted projects.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • o57vsblobprodeus2125.blob.core.windows.net
    • Triggering command: dotnet restore --no-dependencies /home/REDACTED/work/MSBuildSdkExtras/.codeql-scratch/dbs/csharp/working/011FD41CC6F94F07FDAE78E0AF58AFF4/missingpackages_workingdir --packages /home/REDACTED/work/MSBuildSdkExtras/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/MSBuildSdkExtras/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>NET6_0 constants not properly defined</issue_title>
<issue_description># Context

For LibVLCSharp, we need to support Xamarin.Forms projects and old .net versions as well as the new .net6.0 tfms

The issue

A repro can be found here : https://github.com/jeremyVignelles/repro-tfm-msbuild-sdk-extras

It seems that NET6_0_OR_GREATER is not defined anywhere and NET6_0 is only defined in net6.0 and not net6.0-windows

It also seem that I can't use the new top-level statements in such projects.

</issue_description>

Comments on the Issue (you are @copilot in this section)

@clairernovotny I noticed this earlier this week as well.

@dsplaisted Before I hunt this down, do you recall where these are defined or what controls them being defined?</comment_new>
<comment_new>@clairernovotny
As a workaround, you should be able to set the DisableImplicitFrameworkDefines property to false. For some reason, the extras is setting that to true here:

https://github.com/novotnyllc/MSBuildSdkExtras/blob/main/Source/MSBuild.Sdk.Extras/Build/Platforms.targets#L45

I'm not sure exactly why anymore and I'll need to look closer to see what the side-effects are for all of the other project types.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Explicitly set DisableImplicitFrameworkDefines=false in Platforms.targets
- This ensures Microsoft.NET.Sdk adds implicit framework defines like NET6_0, NET6_0_OR_GREATER, etc.
- Add test to verify implicit framework defines work correctly for net8.0 and net8.0-windows

Co-authored-by: clairernovotny <[email protected]>
@clairernovotny clairernovotny marked this pull request as ready for review November 1, 2025 21:40
Copilot AI review requested due to automatic review settings November 1, 2025 21:40
Copilot AI changed the title [WIP] Fix NET6_0 constants not properly defined for Xamarin.Forms Fix implicit framework defines (NET6_0, NET6_0_OR_GREATER) not being defined Nov 1, 2025
Copilot AI requested a review from clairernovotny November 1, 2025 21:43
Copy link

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 enables implicit framework defines (like NET8_0, NET8_0_OR_GREATER, NET8_0_WINDOWS) from the Microsoft.NET.Sdk to work correctly alongside the custom defines provided by MSBuild.Sdk.Extras. Previously, these standard SDK defines were being disabled.

Key changes:

  • Explicitly sets DisableImplicitFrameworkDefines to false to ensure Microsoft.NET.Sdk adds its standard framework defines
  • Adds a test project to verify that implicit framework defines are working correctly

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Source/MSBuild.Sdk.Extras/Build/Platforms.targets Uncomments and modifies the DisableImplicitFrameworkDefines property to explicitly set it to false, ensuring Microsoft.NET.Sdk adds implicit framework defines
Tests/ImplicitFrameworkDefines/ImplicitFrameworkDefines.csproj Adds test project that validates implicit framework defines work correctly by building for net8.0 and net8.0-windows
Tests/ImplicitFrameworkDefines/Class1.cs Adds test class with preprocessor directives that will fail compilation if the required defines are missing

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

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.

NET6_0 constants not properly defined

2 participants