1

我的应用程序包含一个主文件,允许使用 Codedom 生成可执行文件。这个可执行文件是从我的文件中生成的Source.vb

我想在后者中使用外部库。特别是,这是 Rebex:这将允许我从服务器 sFTP 下载文件。这是我的 Codedom 设置:

Public Shared Function compile_Stub(ByVal input As String, ByVal output As String, ByVal resources As String, ByVal showError As Boolean, Optional ByVal icon_Path As String = Nothing) As Boolean

    Dim provider_Args As New Dictionary(Of String, String)()
    provider_Args.Add("CompilerVersion", "v3.5")

    Dim provider As New Microsoft.VisualBasic.VBCodeProvider(provider_Args)
    Dim c_Param As New Compiler.CompilerParameters
    Dim c_Args As String = " /target:winexe /platform:x86 /optimize "

    If Not icon_Path = Nothing Then
        c_Args = c_Args & "/win32icon:" & icon_Path
    End If

    c_Param.GenerateExecutable = True
    c_Param.OutputAssembly = output
    c_Param.EmbeddedResources.Add(resources)
    c_Param.CompilerOptions = c_Args
    c_Param.IncludeDebugInformation = False
    c_Param.ReferencedAssemblies.AddRange({"C:\Users\marsh\Desktop\project\Galaxy\packages\Rebex.Common.5.0.7119\lib\net35\Rebex.Common.dll", "C:\Users\marsh\Desktop\project\Galaxy\packages\Rebex.Networking.5.0.7119\lib\net35\Rebex.Networking.dll", "C:\Users\marsh\Desktop\project\Galaxy\packages\Rebex.Sftp.5.0.7119\lib\net35\Rebex.Sftp.dll", "mscorlib.dll", "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Management.dll", "System.Dll", "System.Drawing.Dll", "System.Windows.Forms.Dll", "System.Data.Dll", "System.Xml.Dll"})
    c_Param.GenerateInMemory = True
    Dim c_Result As Compiler.CompilerResults = provider.CompileAssemblyFromSource(c_Param, input)
    If c_Result.Errors.Count = 0 Then
        Return True
    Else
        If showError Then
            For Each _Error As Compiler.CompilerError In c_Result.Errors
                MessageBox.Show("ERREUR de compilation" & vbNewLine &
          "FileName: " & _Error.FileName & vbNewLine &
          "Ligne: " & _Error.Line & vbNewLine & "ErrorText: " &
          _Error.ErrorText & vbNewLine &
          "Column: " &
          _Error.Column & vbNewLine &
          "Type d'erreur (True = avertissement, False = Erreur ): " &
          _Error.IsWarning & vbNewLine & "ErrorNumber: " &
          _Error.ErrorNumber)
            Next
            Return False
        End If
        Return False
    End If

End Function

尽管在我的 Codedom 设置中正确实现了相关库,但当我尝试使用它们时没有任何反应:没有错误,我的应用程序在执行时停止。Rebex 库由 NuGet 安装提供:Rebex.Common.dllRebex.Networking.dllRebex.Sftp.dll。但是,我在代码中编写的用于导入这些库的参数与本文档一致。

当我在我的 Stub 中实现这部分代码时,我的可执行文件冻结Source.vb

        Dim sftp As New Rebex.Net.Sftp()
        sftp.Connect(hostname)

        ' log in
        sftp.Login(username, password)

我真的不明白这个问题来自哪里。没有出现错误的事实更让我感到困惑:我不知道用哪种方法来解决错误。你可以帮帮我吗?

4

0 回答 0