简体   繁体   中英

F# on Linux - targeting net4xx

I've got both mono (5.10.1.20) and dotnet core (2.1.4) installed on my Linux Mint (18.3) machine.

I want to create a project using VS Code Ionide: Ctrl+Shift+P -> F#: New Project -> console. This goes without problems. However, when I try to build it, I get:

error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed.

I take a look at my .fsproj file and indeed - it says:

<TargetFramework>net461</TargetFramework>

However, I found some articles online where people claim to be able to build this without problems (eg Suave-Music-Store tutorial found here:

https://legacy.gitbook.com/book/theimowski/suave-music-store/details )

I'm surely missing something here. So my question is: what exactly (and how to make this work) ?

PS: I was able to hack this a little bit by changing the target framework to "netcoreapp2.0", but still I pretty sure the template should work out of the box.

The other answer is to set the FrameworkPathOverride MsBuild parameter. The assemblies you need are already included in Mono, and you can tell the compiler where to find them by setting FrameworkPathOverride. You can easily do this by including the netfx.props file here: https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/netfx.props . You'd download this to your repo and then add the following line to all of your project files:

<Import Project="..\\netfx.props" />

This is what several projects do. Once either MSBuild changes to look here as well, or an official nuget package comes out, I expect many FSharp projects to switch to one of those methods.

The problem is that you don't have .NET Framework Reference Assemblies. The compiler needs them to in order to know about the .NET Framework APIs your code references.

The good news is that you can get these reference assemblies via nuget

The bad news is that it's not yet published on nuget.org, so you need to add the myget feed to your project

To fix this, add the following to your fsproj

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
    <PackageReference 
          Include="Microsoft.TargetingPack.NETFramework.v4.6.1" 
          Version="1.0.1" ExcludeAssets="All" PrivateAssets="All" />
</ItemGroup>

Then you need to add a Nuget.Config file to your project

<configuration>
 <packageSources>
    <add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
 </packageSources>
</configuration>

With these in place you should be able to build net461 exes and dlls on Linux

Thanks, guys for the responses - let me just post something that I found out on my own. I worked out that adding the following line to my build.sh script does the deal as well: export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/ I guess this is similar to what Chester said, but done in a bit different way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM