【问题标题】:Control temp file usage with codedom使用 codedom 控制临时文件的使用
【发布时间】:2012-08-05 20:00:59
【问题描述】:

我正在使用 .net 和 codedom 在我希望避免(或最好是消除)文件系统访问的环境中工作。

我当前的代码:

Private Sub ProcessCommand(ByVal command As String)
    Dim MyProvider As New VBCodeProvider 
    Dim cp As New CompilerParameters     
    cp.GenerateExecutable = True        
    cp.GenerateInMemory = True           
    Dim TempModuleSource As String = command

    cp.ReferencedAssemblies.Add("System.dll") 
    cp.ReferencedAssemblies.Add("System.Windows.Forms.dll") 
    cp.IncludeDebugInformation = False

    Dim cr As CompilerResults = MyProvider.CompileAssemblyFromSource(cp, TempModuleSource)
    If cr.Errors.Count > 0 Then

        Throw New ArgumentOutOfRangeException("Invalid Expression - please use something VB could evaluate")
    Else

        cr.CompiledAssembly.EntryPoint.Invoke(Nothing, Nothing)
    End If
End Sub

我很惊讶 GenerateInMemory = True 并没有真正让它在内存中生成。相反,二进制文件被编译并存储在一个临时文件中。有没有办法强制codedom将输出存储在内存中?也许通过强制二进制文件不使用临时文件?

【问题讨论】:

    标签: .net vb.net memory codedom


    【解决方案1】:

    这不是一个选项,当前的 VB.NET 和 C# 编译器(vbc.exe 和 csc.exe)只能将程序集生成到磁盘。当 Roslyn 项目发布时,这可能会改变,但那是未来的音乐。

    这根本不会影响编译或程序集加载的效率,您的程序会从内存中加载程序集。文件系统缓存负责这个。

    【讨论】:

    • 谢谢,在这种情况下,我担心的是性能。所以只要在文件系统缓存里,我都不担心
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 2012-09-05
    • 1970-01-01
    相关资源
    最近更新 更多