问题
I have installed Visual Studio 2017 with F# support on my PC and I have MSBuild targets in C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\FSharp
and F# 4.1 SDK in C:\Program Files (x86)\Microsoft SDKs\F#\4.1
I have installed Build Tools for Visual Studio 2017 (from https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15 ) but there is no option to install F# SDK so building F# projects using MSBuild 15 fails.
How can I install F# 4.1 SDK without installing Visual Studio?
回答1:
A short term fix until the SDK can be installed separately is to add a directive to the project file to look in the NuGet packages folder for the Microsoft.FSharp.Targets file. Here are steps I took to fix this:
Ensure your using the new F# project from VS.NET 2017 as its has this directive:
<Import Project="..\packages\FSharp.Compiler.Tools.4.1.17\build\FSharp.Compiler.Tools.props" Condition="Exists('..\packages\FSharp.Compiler.Tools.4.1.17\build\FSharp.Compiler.Tools.props')" />
Replace this section of the project file:
<Choose>
<When Condition="$(TargetFSharpCoreVersion) >= 4.3.0.0 AND $(TargetFSharpCoreVersion) < 4.3.1.0 ">
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildProgramFiles32)\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<When Condition="$(TargetFSharpCoreVersion) >= 4.3.1.0 AND $(TargetFSharpCoreVersion) < 4.4.0.0 ">
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildProgramFiles32)\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<When Condition="$(TargetFSharpCoreVersion) >= 4.4.0.0 AND $(TargetFSharpCoreVersion) < 4.4.1.0 ">
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildProgramFiles32)\Microsoft SDKs\F#\4.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildProgramFiles32)\Microsoft SDKs\F#\4.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
With this XML:
<Choose>
<When Condition="$(TargetFSharpCoreVersion) >= 4.3.0.0 AND $(TargetFSharpCoreVersion) < 4.3.1.0 ">
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildProgramFiles32)\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<When Condition="$(TargetFSharpCoreVersion) >= 4.3.1.0 AND $(TargetFSharpCoreVersion) < 4.4.0.0 ">
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildProgramFiles32)\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<When Condition="$(TargetFSharpCoreVersion) >= 4.4.0.0 AND $(TargetFSharpCoreVersion) < 4.4.1.0 ">
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildProgramFiles32)\Microsoft SDKs\F#\4.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildProgramFiles32)\Microsoft SDKs\F#\4.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<!-- This is needed for TeamCity where F# SDK is only available via NuGet right now - hopefully can be removed at some point once the SDK is available for install -->
<PropertyGroup Condition="!Exists('$(FSharpTargetsPath)')">
<FSharpTargetsPath>$(FscToolPath)\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
Ensure you build server has a restore NuGet packages step prior to doing the build
Ensure you packages file includes: FSharp.Compiler.Tools and FSharp.Core
The reason this works is as follows: This checks to see if the FSharpTargetsPath exists and if not use the packages folder as the source. You don't want to always use the packages folder otherwise on a fresh checkout on a users machine the packages aren't available and the build will fail. For this to work on the build server this assumes you have a step to restore the NuGet packages PRIOR to doing the build.
回答2:
There is an MSI that can be installed, it's not yet been published on MSDN.
But it will be shortly.
You can track the issue here: on GitHub:
"Deploy FSharp Tools MSI to MSDN #2553" https://github.com/Microsoft/visualfsharp/issues/2553
Kevin Ransom
回答3:
It seems it's so new things haven't been updated yet.
- Four step process for installing for a build server (scroll down to Option 3)
http://fsharp.org/use/windows/
(4.0)
- According to the MSDN blog...
https://blogs.msdn.microsoft.com/dotnet/2017/03/07/announcing-f-4-1-and-the-visual-f-tools-for-visual-studio-2017-2/
Seems you at least need .NET Core / CLI
- Searching on Microsoft's site doesn't seem to find anything...
Closest thing would be the 4.0 tools: https://www.microsoft.com/en-us/download/details.aspx?id=48179
- There are alse the raw NuGet packages (4.1)
https://www.nuget.org/packages/FSharp.Compiler.Tools https://www.nuget.org/packages/FSharp.Core
- Bottom line: I think its so new it hasn't been released in a format similar to previous versions yet. I'll keep checking every 24 hours to see if they update it on their website.
来源:https://stackoverflow.com/questions/42679193/install-f-4-1-sdk-on-build-server