在 F# fsx 中找不到命名空间

Namespace not found in F# fsx

我四处搜索过这个,但似乎没有人遇到与 F# .fsx 脚本找不到命名空间完全相同的问题。我有一个构建良好的 Common 项目,并且在另一个项目中被 intellisense 选中,但同一项目中的脚本声明它未定义,即使将鼠标悬停在 #r "Common.dll" 上找到完整路径。常用代码:

namespace Common
open System
open System.Text
open System.Security.Cryptography

module Guid =
  let swapBytes (a: byte[]) = 
Array.concat [ Array.rev a.[..3] ; Array.rev a.[4..5] ; Array.rev a.[6..7]; a.[8..15] ]

// Implementaion of http://www.ietf.org/rfc/rfc4122.txt section 4.3 version 5 (Name Based using SHA-1)
// Based on C# at https://github.com/LogosBible/Logos.Utility/blob/master/src/Logos.Utility/GuidUtility.cs
type System.Guid with
  static member FromName (guid:System.Guid) (name:string) =
    let nameBytes: byte[] = Encoding.UTF8.GetBytes name
    let nameSpaceBytes = guid.ToByteArray() |> swapBytes

    use algorithm = SHA1.Create()
    algorithm.TransformBlock (nameSpaceBytes, 0, nameSpaceBytes.Length, null, 0) |> ignore
    algorithm.TransformFinalBlock(nameBytes, 0, nameBytes.Length) |> ignore
    let hash = algorithm.Hash;

    let newGuid = Array.create 16 0uy
    Array.Copy(hash, 0, newGuid, 0, 16)

    Array.set newGuid 6 ((newGuid.[6] &&& 0x0Fuy) ||| (5uy <<< 4))
    Array.set newGuid 8 ((newGuid.[8] &&& 0x3Fuy) ||| 0x80uy)

    newGuid |> swapBytes |> System.Guid

.fsx 内容:

#I @"..\Common\bin\Debug"
#r "Common.dll"
open Common

let NamedGuid = System.Guid.FromName (Guid("190bbe82-5692-43a4-b825-079f41fc55c0"))

这是在 VS2015 中。缺少什么?

您还需要打开Guid模块,或者使用[<AutoOpen>]属性对其进行注释。这将解析对 System.Guid.FromName.

的引用

完成后,您还需要打开 System 命名空间才能访问 Guid 构造函数(或直接调用 System.Guid)。