2012-04-15 4 views
2

.fsx 스크립트에서 사전 컴파일 정규식을 실험하고 있습니다. 그러나 생성 된 어셈블리의 .dll 파일 위치를 지정하는 방법을 알 수 없습니다. Regex.CompileToAssembly에 의해 사용 된 AssemblyName 인스턴스에서 CodeBase과 같은 속성을 설정하려고 시도했지만 아무 소용이 없습니다.Regex.CompileToAssembly .dll 파일 위치를 설정하는 방법

open System.Text.RegularExpressions 

let rcis = [| 
    new RegexCompilationInfo(
     @"^NumericLiteral([QRZING])$", 
     RegexOptions.None, 
     "NumericLiteral", 
     "Swensen.Unquote.Regex", 
     true 
    ); 
|] 

let an = new System.Reflection.AssemblyName("Unquote.Regex"); 
an.CodeBase <- __SOURCE_DIRECTORY__ + "\\" + "Unquote.Regex.dll" 
Regex.CompileToAssembly(rcis, an) 

내가 FSI이를 실행하고있어 내가 an을 평가할 때 나는 다음을 참조하십시오 : 여기가 무슨 \ 스티븐을 \ 사용자 :

> an;; 
val it : System.Reflection.AssemblyName = 
    Unquote.Regex 
    {CodeBase = "C:\Users\Stephen\Documents\Visual Studio 2010\Projects\Unquote\code\Unquote\Unquote.Regex.dll"; 
    CultureInfo = null; 
    EscapedCodeBase = "C:%5CUsers%5CStephen%5CDocuments%5CVisual%20Studio%202010%5CProjects%5CUnquote%5Ccode%5CUnquote%5CUnquote.Regex.dll"; 
    Flags = None; 
    FullName = "Unquote.Regex"; 
    HashAlgorithm = None; 
    KeyPair = null; 
    Name = "Unquote.Regex"; 
    ProcessorArchitecture = None; 
    Version = null; 
    VersionCompatibility = SameMachine;} 

그러나 다시, 나는 C가 표시되지 않습니다 \ Documents \ Visual Studio 2010 \ Projects \ Unquote \ code \ Unquote \ Unquote.Regex.dll 내가 원하는 것처럼. 내 C 드라이브에서 Unquote.Regex.dll을 검색하면 일부 임시 AppData 폴더에서 찾을 수 있습니다.

따라서 어떻게 Regex.CompileToAssembly에 의해 생성 된 어셈블리의 .dll 파일 위치를 올바르게 지정할 수 있습니까?

답변

4

CompileToAssembly는 CodeBase 또는 AssemblyName의 다른 속성을 고려하지 않고 결과 어셈블리를 현재 디렉터리에 저장하는 것 같습니다. System.Environment.CurrentDirectory를 적절한 위치로 설정하고 저장 한 후에 되돌려 놓으십시오.

open System.Text.RegularExpressions 

type Regex with 
    static member CompileToAssembly(rcis, an, targetFolder) = 
     let current = System.Environment.CurrentDirectory 
     System.Environment.CurrentDirectory <- targetFolder 
     try 
      Regex.CompileToAssembly(rcis, an) 
     finally 
      System.Environment.CurrentDirectory <- current 


let rcis = [| 
    new RegexCompilationInfo(
     @"^NumericLiteral([QRZING])$", 
     RegexOptions.None, 
     "NumericLiteral", 
     "Swensen.Unquote.Regex", 
     true 
    ); 
|] 

let an = new System.Reflection.AssemblyName("Unquote.Regex"); 
Regex.CompileToAssembly(rcis, an, __SOURCE_DIRECTORY__) 
+0

우수 감사합니다! –

관련 문제