码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-09 21:30:39      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   使用   os   io   strong   

《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:\ProgramFiles\Microsoft SDKs\F#\2.0\Framework\v4.0";
                 "C:\ProgramFiles\Microsoft SDKs\F#\3.0\Framework\v4.0";
                 "C:\ProgramFiles\Microsoft SDKs\F#\3.1\Framework\v4.0";
                 "C:\ProgramFiles\Microsoft SDKs\F#\4.0\Framework\v4.0";
                 "C:\ProgramFiles (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0";
                 "C:\ProgramFiles (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0";
                 "C:\ProgramFiles (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0";
                 "C:\ProgramFiles (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0";
                 )
    $FscPath| % { if (Test-Path $_) { $env:Path = $env:Path+ ";" + $_  } }

    if ($isAMD64)
    {
        $FSharpCorePath= @(
            "C:\ProgramFiles (x86)\ReferenceAssemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.0.0\FSharp.Core.dll"
        )

        if ($is32)
        {
           $mscorlibPath= @(
                "C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll"
            )
        }
        else
        {
            $mscorlibPath= @(
                "C:\ProgramFiles (x86)\ReferenceAssemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll"
            )
        }
    }
    else
    {
        if ($is32)
        {
            $FSharpCorePath= @(
                "C:\ProgramFiles (x86)\ReferenceAssemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.0.0\FSharp.Core.dll"
                )
            $mscorlibPath= @(
                "C:\ProgramFiles (x86)\ReferenceAssemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll";
                "C:\ProgramFiles (x86)\ReferenceAssemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client5\mscorlib.dll"

            )

        }
        else
        {
            $FSharpCorePath= @(
                "C:\ProgramFiles\ReferenceAssemblies\Microsoft\FSharp\3.0\Runtime\v4.0\FSharp.Core.dll";
                "C:\ProgramFiles\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.0.0\FSharp.Core.dll";
                )

            $mscorlibPath= @(           
                "C:\ProgramFiles\ReferenceAssemblies\Microsoft\Framework\.NETFramework\v3.0\mscorlib.dll"
                "C:\ProgramFiles\ReferenceAssemblies\Microsoft\Framework\.NETFramework\v3.5\mscorlib.dll"
                "C:\ProgramFiles\ReferenceAssemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll"
                "C:\ProgramFiles\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.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.0\bin\FSharp.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:USERPROFILE\Desktop\Data.fs" | Out-String
$references = @("C:\FSharp.Data\bin\FSharp.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


《powershell 的版本所引起的加载 FSharp 编译器问题》基本解决,布布扣,bubuko.com

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

标签:des   style   http   color   使用   os   io   strong   

原文地址:http://blog.csdn.net/hadstj/article/details/38459759

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!