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
8 changes: 6 additions & 2 deletions src/FSharp.Build/Microsoft.FSharp.Core.NetSdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<PropertyGroup Condition="'$(_FSCorePackageVersionSet)' != 'true'">
<_FSCorePackageVersionSet>true</_FSCorePackageVersionSet>
<PropertyGroup Condition="'$(FSCorePackageVersionSet)' != 'true'">
<FSCorePackageVersionSet>true</FSCorePackageVersionSet>
<FSCorePackageVersion>{{FSCorePackageVersionValue}}</FSCorePackageVersion>
<_FSharpCoreLibraryPacksFolder Condition="'$(_FSharpCoreLibraryPacksFolder)' == ''">$([MSBuild]::EnsureTrailingSlash('$(MSBuildThisFileDirectory)'))library-packs</_FSharpCoreLibraryPacksFolder>
</PropertyGroup>

<PropertyGroup Condition="'$(FSCorePackageVersionSet)' == 'true' and '$(FSCorePackageVersion)' != '' and !$(FSCorePackageVersion.Contains('{'))">
<FSharpCoreMaximumMajorVersion Condition="'$(FSharpCoreMaximumMajorVersion)' == ''">$([System.Version]::Parse('$(FSCorePackageVersion.Split('-')[0])').Major)</FSharpCoreMaximumMajorVersion>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions src/FSharp.Build/Microsoft.FSharp.NetSdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,29 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
<PathMap>@(_TopLevelSourceRoot->'%(EscapedKey)=%(EscapedValue)', ','),$(PathMap)</PathMap>
</PropertyGroup>
</Target>

<!--
Warn if resolved FSharp.Core major version exceeds SDK's compiler version.
-->
<Target Name="_CheckForUnsupportedFSharpCoreVersion"
AfterTargets="ResolvePackageAssets"
Condition="'$(ValidateFSharpCoreVersion)' != 'false' and '$(FSharpCoreMaximumMajorVersion)' != ''">

<ItemGroup>
<_ResolvedFSharpCore Include="@(ReferencePath)"
Condition="'%(ReferencePath.NuGetPackageId)' == 'FSharp.Core'" />
</ItemGroup>

<PropertyGroup Condition="'@(_ResolvedFSharpCore->Count())' == '1'">
<_ResolvedFSharpCoreVersion>@(_ResolvedFSharpCore->'%(NuGetPackageVersion)')</_ResolvedFSharpCoreVersion>
<_ResolvedFSharpCoreMajor>$([System.Version]::Parse('$(_ResolvedFSharpCoreVersion.Split('-')[0])').Major)</_ResolvedFSharpCoreMajor>
<_FSharpCoreVersionTooHigh Condition="$(_ResolvedFSharpCoreMajor) &gt; $(FSharpCoreMaximumMajorVersion)">true</_FSharpCoreVersionTooHigh>
</PropertyGroup>

<Warning
Condition="'$(_FSharpCoreVersionTooHigh)' == 'true'"
Code="FSSDK0001"
Text="The referenced FSharp.Core $(_ResolvedFSharpCoreVersion) has a higher major version ($(_ResolvedFSharpCoreMajor)) than this SDK supports ($(FSharpCoreMaximumMajorVersion)). This may cause compilation errors or runtime failures." />

</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project ToolsVersion="4.0" DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestFSCorePackageVersion>8.0.100</TestFSCorePackageVersion>
</PropertyGroup>
<Import Project="FSharpCoreVersionTest.props" />
<PropertyGroup>
<TestResolvedVersion>9.0.0</TestResolvedVersion>
<ExpectedMaxMajor>8</ExpectedMaxMajor>
<ExpectWarning>true</ExpectWarning>
</PropertyGroup>
<Import Project="FSharpCoreVersionTest.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project ToolsVersion="4.0" DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestFSCorePackageVersion>9.0.100</TestFSCorePackageVersion>
</PropertyGroup>
<Import Project="FSharpCoreVersionTest.props" />
<PropertyGroup>
<TestResolvedVersion>8.0.100</TestResolvedVersion>
<ExpectedMaxMajor>9</ExpectedMaxMajor>
<ExpectWarning>false</ExpectWarning>
</PropertyGroup>
<Import Project="FSharpCoreVersionTest.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project ToolsVersion="4.0" DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestFSCorePackageVersion>9.0.100-preview.1</TestFSCorePackageVersion>
</PropertyGroup>
<Import Project="FSharpCoreVersionTest.props" />
<PropertyGroup>
<TestResolvedVersion>10.0.0-beta.1</TestResolvedVersion>
<ExpectedMaxMajor>9</ExpectedMaxMajor>
<ExpectWarning>true</ExpectWarning>
</PropertyGroup>
<Import Project="FSharpCoreVersionTest.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project ToolsVersion="4.0" DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestFSCorePackageVersion>9.0.100</TestFSCorePackageVersion>
</PropertyGroup>
<Import Project="FSharpCoreVersionTest.props" />
<PropertyGroup>
<TestResolvedVersion>9.0.200</TestResolvedVersion>
<ExpectedMaxMajor>9</ExpectedMaxMajor>
<ExpectWarning>false</ExpectWarning>
</PropertyGroup>
<Import Project="FSharpCoreVersionTest.targets" />
</Project>
23 changes: 23 additions & 0 deletions tests/fsharp/SDKTests/tests/FSharpCoreVersionTest.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(FSharpRepositoryPath)\eng\Versions.props" />

<PropertyGroup>
<TargetFramework Condition="'$(TargetFramework)' == ''">net10.0</TargetFramework>
<_TargetFrameworkVersionWithoutV>10.0</_TargetFrameworkVersionWithoutV>
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
<TargetsDirectory>$(FSharpRepositoryPath)\artifacts\bin\FSharpSuite.Tests\$(Configuration)\$(TARGETFRAMEWORK)</TargetsDirectory>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<OutputPath>$(MSBuildThisFileDirectory)</OutputPath>
</PropertyGroup>

<!-- Override SDK version BEFORE import -->
<PropertyGroup Condition="'$(TestFSCorePackageVersion)' != ''">
<FSCorePackageVersion>$(TestFSCorePackageVersion)</FSCorePackageVersion>
<FSCorePackageVersionSet>true</FSCorePackageVersionSet>
</PropertyGroup>

<Import Project="$(TargetsDirectory)\Microsoft.FSharp.NetSdk.props" />

</Project>
27 changes: 27 additions & 0 deletions tests/fsharp/SDKTests/tests/FSharpCoreVersionTest.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(TargetsDirectory)\Microsoft.FSharp.NetSdk.targets" />

<Target Name="Test">
<Message Importance="High" Text="Testing: $(MSBuildProjectName)" />

<!-- Simulate version comparison -->
<PropertyGroup Condition="'$(TestResolvedVersion)' != ''">
<_TestResolvedMajor>$([System.Version]::Parse('$(TestResolvedVersion.Split('-')[0])').Major)</_TestResolvedMajor>
<_TestShouldWarn Condition="$(_TestResolvedMajor) &gt; $(FSharpCoreMaximumMajorVersion)">true</_TestShouldWarn>
</PropertyGroup>

<!-- Assertions -->
<Error Condition="'$(ExpectedMaxMajor)' != '' and '$(FSharpCoreMaximumMajorVersion)' != '$(ExpectedMaxMajor)'"
Text="FSharpCoreMaximumMajorVersion: expected '$(ExpectedMaxMajor)' actual '$(FSharpCoreMaximumMajorVersion)'" />

<Error Condition="'$(ExpectWarning)' == 'true' and '$(_TestShouldWarn)' != 'true'"
Text="Expected warning but didn't get one" />

<Error Condition="'$(ExpectWarning)' == 'false' and '$(_TestShouldWarn)' == 'true'"
Text="Did not expect warning but got one" />

<Message Importance="High" Text="PASSED: $(MSBuildProjectName)" />
</Target>

</Project>
Loading