Warn when FSharp.Core major version exceeds SDK compiler version #19183
+129
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Emits
FSSDK0001warning when a project references (directly or transitively) an FSharp.Core package with a higher major version than the SDK's compiler supports.Implementation
Props file (
Microsoft.FSharp.Core.NetSdk.props):_FSCorePackageVersionSet→FSCorePackageVersionSet(now public for test hooks)FSharpCoreMaximumMajorVersionproperty computed from SDK'sFSCorePackageVersion.Split('-')[0]before version parsingTargets file (
Microsoft.FSharp.NetSdk.targets):_CheckForUnsupportedFSharpCoreVersiontarget (runs afterResolvePackageAssets)"The referenced FSharp.Core X.Y.Z has a higher major version (X) than this SDK supports (N)..."<ValidateFSharpCoreVersion>false</ValidateFSharpCoreVersion>Test Coverage
Four MSBuild test projects validate:
Example
Build output with SDK 10.x:
Original prompt
FSharp.Core Version Validation
Goal
Warn (
FSSDK0001) when a project references FSharp.Core with a higher major version than the SDK's compiler supports (directly or via transitive dependency).Scenarios
Implementation
1. Modify Props File
File:
src/FSharp.Build/Microsoft.FSharp.Core.NetSdk.propsCurrent content (lines 23-27):
Replace with:
Changes:
_FSCorePackageVersionSet→FSCorePackageVersionSet(public, for testability)FSharpCoreMaximumMajorVersioncomputation.Split('-')[0]strips prerelease suffix (required becauseSystem.Version.Parsedoesn't handle semver)2. Add Validation Target
File:
src/FSharp.Build/Microsoft.FSharp.NetSdk.targetsAdd before closing
</Project>tag (after line 221):Key points:
AfterTargets="ResolvePackageAssets"— runs after NuGet resolves all packages (including transitives)%(ReferencePath.NuGetPackageVersion)— gets the resolved package version<ValidateFSharpCoreVersion>false</ValidateFSharpCoreVersion>Testing
Test Location
Directory:
tests/fsharp/SDKTests/tests/Test runner:
tests/fsharp/SDKTests/AllSdkTargetsTests.projExisting patterns to follow:
tests/fsharp/SDKTests/tests/PackageTest.propstests/fsharp/SDKTests/tests/PackageTest.targetstests/fsharp/SDKTests/tests/SetImplicitReferenceTest.projNew Test Files to Create
tests/fsharp/SDKTests/tests/FSharpCoreVersionTest.props