• 《powershell 的版本号所引起的载入 FSharp 编译器问题》基本解决


    《powershell 的版本号所引起的载入 FSharp 编译器问题》基本解决


    1、FSharp.Core.dll。不光要 Add-Type,还要在编译中引用。可是,在 VS2012 的环境下,就不须要引用,百思不得其解;

    2、理顺了大部分系统引用的地址。


    Function Compiler-FSharp([string] $fSharpCode,[Array]$References)
    {
        # 推断 Powershell 的版本号
        $isAMD64= ($env:PROCESSOR_ARCHITECTURE).Contains( "AMD64" )
        $is32= $PSHOME.Contains("SysWOW64" )
        $ra= New-Object Collections.ArrayList

        # 添加 Path for FSC.exe
        $FscPath= @("C:ProgramFilesMicrosoft SDKsF#2.0Frameworkv4.0";
                     "C:ProgramFilesMicrosoft SDKsF#3.0Frameworkv4.0";
                     "C:ProgramFilesMicrosoft SDKsF#3.1Frameworkv4.0";
                     "C:ProgramFilesMicrosoft SDKsF#4.0Frameworkv4.0";
                     "C:ProgramFiles (x86)Microsoft SDKsF#3.0Frameworkv4.0";
                     "C:ProgramFiles (x86)Microsoft SDKsF#3.0Frameworkv4.0";
                     "C:ProgramFiles (x86)Microsoft SDKsF#3.1Frameworkv4.0";
                     "C:ProgramFiles (x86)Microsoft SDKsF#4.0Frameworkv4.0";
                     )
        $FscPath| % { if (Test-Path $_) { $env:Path = $env:Path+ ";" + $_  } }

        if ($isAMD64)
        {
            $FSharpCorePath= @(
                "C:ProgramFiles (x86)ReferenceAssembliesMicrosoftFSharp.NETFrameworkv4.04.3.0.0FSharp.Core.dll"
            )

            if ($is32)
            {
               $mscorlibPath= @(
                    "C:WindowsMicrosoft.NETFrameworkv4.0.30319mscorlib.dll"
                )
            }
            else
            {
                $mscorlibPath= @(
                    "C:ProgramFiles (x86)ReferenceAssembliesMicrosoftFramework.NETFrameworkv4.5mscorlib.dll"
                )
            }
        }
        else
        {
            if ($is32)
            {
                $FSharpCorePath= @(
                    "C:ProgramFiles (x86)ReferenceAssembliesMicrosoftFSharp.NETFrameworkv4.04.3.0.0FSharp.Core.dll"
                    )
                $mscorlibPath= @(
                    "C:ProgramFiles (x86)ReferenceAssembliesMicrosoftFramework.NETFrameworkv4.5mscorlib.dll";
                    "C:ProgramFiles (x86)ReferenceAssembliesMicrosoftFramework.NETFrameworkv3.5ProfileClient5mscorlib.dll"

                )

            }
            else
            {
                $FSharpCorePath= @(
                    "C:ProgramFilesReferenceAssembliesMicrosoftFSharp3.0Runtimev4.0FSharp.Core.dll";
                    "C:ProgramFilesReference AssembliesMicrosoftFSharp.NETFrameworkv4.04.3.0.0FSharp.Core.dll";
                    )

                $mscorlibPath= @(           
                    "C:ProgramFilesReferenceAssembliesMicrosoftFramework.NETFrameworkv3.0mscorlib.dll"
                    "C:ProgramFilesReferenceAssembliesMicrosoftFramework.NETFrameworkv3.5mscorlib.dll"
                    "C:ProgramFilesReferenceAssembliesMicrosoftFramework.NETFrameworkv4.0mscorlib.dll"
                    "C:ProgramFilesReference AssembliesMicrosoftFramework.NETFrameworkv4.5mscorlib.dll"
                )
           }
        }


        $FSharpCorePath| % { if(Test-Path( $_ )) { Add-Type -Path $_ } }
        $ra.AddRange( @( $mscorlibPath  | ? { Test-Path( $_ ) } | Select-Object -First1 ) )
        $ra.AddRange( @( $FSharpCorePath | ?

    {Test-Path($_ ) } | Select-Object -First 1 ) )


        if ($references.Count-ge 1)
        {
            $ra.AddRange($References)
            $references|  % { if(Test-Path( $_ )) { Add-Type -Path$_ } else{ Add-Type -AssemblyName $_} }
        }
        # 载入 FSharp.Compiler.CodeDom.dll
        Add-Type -Path C:FSharpPowerPack-4.0.0.0inFSharp.Compiler.CodeDom.dll
        $provider= New-ObjectMicrosoft.FSharp.Compiler.CodeDom.FSharpCodeProvider
        <#
        假设要使用-CompilerParameters
        与-ReferencedAssemblies 不能同一时候使用
        $cp= New-ObjectSystem.CodeDom.Compiler.CompilerParameters
        $cp.CompilerOptions= "--platform:x86"
        #>
        $fSharpType= Add-Type-TypeDefinition $fSharpCode -CodeDomProvider $provider -ReferencedAssemblies $ra -ErrorActionIgnore -PassThru | where { $_.IsPublic }
        $fSharpType
    }


    ============================

    ######################
    FSharp.Data
    ######################


    $fSharpCode = Get-Content"$env:USERPROFILEDesktopData.fs" | Out-String
    $references = @("C:FSharp.DatainFSharp.Data.dll")

    Compiler-FSharp $fSharpCode $references

    [Test]::http("http://www.baidu.com").Body.item

    ============================

    Data.fs:

    module Test

    open FSharp.Data
    //open FSharp.Net
    // FSharp.Data 新版本号中所有的函数所有归到 Data 命名空间下了。

    let http (url:string) = Http.Request url


  • 相关阅读:
    dp第三题
    近期(2012/5/15)
    HTML5 地理位置定位(HTML5 Geolocation)原理及应用【转】
    xml 中如何正确使用 & 符号
    Python进阶07 函数对象【转】
    Android 快捷小工具
    解决数据库乱码问题【转】
    Android APK反编译详解(附图)
    字符串转日期【20080808080808】
    HTML+5+从入门到精通
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5127061.html
Copyright © 2020-2023  润新知