Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Source/MSBuild.Sdk.Extras/Build/Platforms.targets
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@

<!-- The conditional compilation symbols defined in the above import and the property-group flows to the Main SDK -->
<PropertyGroup Condition="'$(DisableImplicitFrameworkDefines)' != 'true'">
<!--<DisableImplicitFrameworkDefines>true</DisableImplicitFrameworkDefines> -->
<!-- Explicitly set to false to ensure Microsoft.NET.Sdk adds implicit framework defines like NET6_0, NET6_0_OR_GREATER, etc. -->
<DisableImplicitFrameworkDefines>false</DisableImplicitFrameworkDefines>
<VersionlessImplicitFrameworkDefine>$(ImplicitFrameworkIdentifierDefine)</VersionlessImplicitFrameworkDefine>
</PropertyGroup>

Expand Down
18 changes: 18 additions & 0 deletions Tests/ImplicitFrameworkDefines/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace ImplicitFrameworkDefines
{
public class TestClass
{
#if !NET8_0 && !NET8_0_OR_GREATER
#error NET8_0 and NET8_0_OR_GREATER must be defined
#endif

#if NET8_0_WINDOWS
// This should only compile for net8.0-windows
public const string Platform = "Windows";
#else
public const string Platform = "CrossPlatform";
#endif
}
}
18 changes: 18 additions & 0 deletions Tests/ImplicitFrameworkDefines/ImplicitFrameworkDefines.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>

<Import Project="$(MSBuildThisFileDirectory)..\..\Source\MSBuild.Sdk.Extras\Sdk\Sdk.props" />

<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-windows</TargetFrameworks>
<OutputType>Library</OutputType>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\Source\MSBuild.Sdk.Extras\Sdk\Sdk.targets" />

<Target Name="Test" DependsOnTargets="Build">
<!-- The build itself will fail if the #error directive in Class1.cs is triggered -->
<!-- This means if we get here, the implicit defines are working -->
<Message Text="✓ Implicit framework defines test passed - build succeeded without errors" Importance="High" />
</Target>

</Project>
Loading