Referencing an x64 dll file works in C# but does not work in F#

空扰寡人 提交于 2019-12-23 18:32:24

问题


I have created two brand new solutions using the latest VS 2010:

  • C# console application
  • F# console application

I have referenced two x64 dll files: Kitware.VTK.dll and Kitware.mummy.Runtime.dll
(can be downloaded here: http://www.kitware.com/products/avdownload.php )

The C# VS 2010 finds the namespace when I write using Kitware.
The F# VS 2010 does not find the namespace when I write open Kitware.

The x86 version works fine in F#. Any idea why is that and how to make the Kitware x64 work in F#?


回答1:


It's probably due to the bug described here:

F# project references not working when targeting x64 platform in Visual Studio 2010

They say it will be fixed in the next release of VS.

be well -h-




回答2:


F# console applications default to targeting x86 rather than Any CPU. If you haven't changed that, then the F# project won't work with an x64 library.




回答3:


I think I may have a fix for that. It requires manually editing your fsproj file.

Add this after the <PropertyGroup> items and before the first <Import>.

  <PropertyGroup Condition="'$(Platform)' == 'x64'">
    <!--
    Assembly resolution using msbuild is broken for the x64 platform in F# 2.0.
    See https://connect.microsoft.com/VisualStudio/feedback/details/588317/f-project-references-not-working-when-targeting-x64-platform-in-visual-studio-2010
    We use simple resolution with a hard-coded list of paths to look for the dlls instead.
    -->
    <NoStdLib>true</NoStdLib>
    <OtherFlags>--simpleresolution</OtherFlags>
    <ReferencePath>C:\Windows\Microsoft.NET\Framework64\v3.5;C:\Windows\Microsoft.NET\Framework64\v2.0.50727</ReferencePath>
  </PropertyGroup>

Note that OtherFlags is overwritten, which was OK for me as it was empty. If it's used, you should probably append to the variable instead. It would be nice to use Microsoft.Build.Tasks for the list of paths, instead of using a hard-coded list, but I haven't been able to get that to work.



来源:https://stackoverflow.com/questions/6661833/referencing-an-x64-dll-file-works-in-c-sharp-but-does-not-work-in-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!