f# - 为通用应用程序(又名商店应用程序或 Windows 应用程序或 WinRT 应用程序)创建 F# PCL

标签 f# msbuild windows-runtime win-universal-app

从 Visual Studio 2013 Update 2 开始,可以创建可引用 Windows 运行时类型(以前不可能)的可移植类库 (PCL),只要它们仅针对 Windows 8.1 和 Windows Phone 8.1 而没有其他目标。

我通过添加 C# 类库(可移植到通用应用程序)在 C# 中尝试了这个,它可以工作 ,这意味着您可以使用和生成 Windows 运行时类型,就像项目是 Windows 应用程序或 Windows 运行时组件一样。

由于 F# 也支持 PCL 并且 Windows 8.1 和 Windows Phone 8.1 是受支持的目标,我想用 F# PCL 实现相同的目标(如果可能)。虽然 Visual Studio 2013 更新 4 不提供创建仅面向 Windows 8.1 和 Windows Phone 8.1 的 F# PCL,但可以修改 F# PCL 的 .fsproj 文件以将 C# PCL 的 .csproj 文件与那些目标使用 Visual Studio 创建。这需要将 XML 元素更改为以下内容:

<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile32</TargetFrameworkProfile>

并将以下内容添加到 <ItemGroup>
<TargetPlatform Include="WindowsPhoneApp, Version=8.1" />
<TargetPlatform Include="Windows, Version=8.1" />

在这些更改之后,我能够像在 C# PCL 中一样在 F# PCL 中使用和生成 Windows 运行时类型(没有来自 F# PCL 或 C#(通用)Windows 应用程序中的 Visual Studio 的提示),但是当我实际运行(通用)Windows 应用程序时) Windows 应用程序我收到以下异常 当从 C#(通用)Windows 应用程序在 F# PCL 中调用使用 Windows 运行时类型的函数时:

An exception of type 'System.IO.FileNotFoundException' occurred in [application name].exe but was not handled in user code

Additional information: Could not load file or assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.



当我在 Visual Studio 的解决方案资源管理器中检查引用时,C# PCL 显示了一个名为 Windows 的引用,而 F# PCL 中缺少该引用。该引用的引用属性如下所示:

properties of Windows reference

我尝试通过添加手动将此引用添加到 F# PCL 的 .fsproj 文件
<Reference Include="C:\Program Files (x86)\Microsoft SDKs\Portable\v12.0\110C4FEFF2BA61C0746933A9ED6E248D\Windows.winmd" />

<ItemGroup> .此后,该引用确实显示在解决方案资源管理器中的 F# PCL 中,并具有以下引用属性:

enter image description here

但不能解决问题。也就是说,我仍然得到与以前相同的异常。

我还尝试通过 Visual Studio 的解决方案资源管理器的上下文菜单复制和粘贴 Windows 引用,但它提示一条错误消息。

您知道如何将 Windows 引用正确添加到 F# PCL 吗?这真的很棒,因为这将使几乎完全用 F# 编写(通用)Windows 应用程序成为可能!如果您知道这是不可能的,那么您能否解释一下是什么阻止了这一切?

编辑:改进了异常消息的格式

最佳答案

您正在制作一个可移植的类库。 F# 不支持 Windows 商店应用程序,因此在这种情况下使用 F# 的唯一方法是从 C# 调用它。如果你成功了,你将是任何人中的第一个。

关于f# - 为通用应用程序(又名商店应用程序或 Windows 应用程序或 WinRT 应用程序)创建 F# PCL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29932759/

相关文章:

visual-studio - Visual Studio 2010 智能感知 : hints on F# operators

c# - VS2005 : How to automatically generate a build number with date?

c# - 如何更新缓存页面中 UI 中的数据绑定(bind)元素?

windows - 在 Windows 8 Metro 上编译 OpenSSL

c# - WinRt C#音频库

list - F#:如何打印完整列表(Console.WriteLine() 仅打印前三个元素)

f# - 使用计算表达式避免厄运金字塔?

wpf - 使用 XAML 标记的 F# 事件处理程序

.net - MSBuild - 为解决方案设置属性

.net - 自动更新带有 TFS 修订版的文件?