Quellcode per Anwendung compilieren

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 54 Antworten in diesem Thema. Der letzte Beitrag () ist von Coder9292.

    Vielleicht liege ich hier falsch, aber nur nochmal zur Klärung damit hier nicht aneinander vorbeigeredet wird. Coder9292 will doch einfach nur ein Compiler erstellen, bzw. den Code einfach an den .Net Compiler weiterreiche. Hier geht es nicht um ein Plugin-System, auch wenn das der Titel dess Themas das vielleicht vermuten lässt.
    @Bluespide genau ich möchte eigentlich nur ein Compiler der meinen Quellcode verarbeitet :)
    Hab den Titel mal angepasst.
    ~Programmieren Sie immer so, als wäre der Typ, der den Code pflegen muss, ein gewaltbereiter Psychopath, der weiß, wo Sie wohnen. ~

    Grüße
    Coder9292

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Coder9292“ ()

    Ich muss den Thread leider wieder aufwecken :D
    Ich habe nun einen Compiler und dieser scheint auch das zu tun was ich brauche aber ich bekomme beim kompilieren des Codes immer Fehler und somit ist die Output EXE schrott ?(

    Hier der Compiler Code:
    Spoiler anzeigen

    Quellcode

    1. Imports System.IO
    2. Imports System.Text
    3. Imports Microsoft.CSharp
    4. Imports System.Resources
    5. Imports System.Diagnostics
    6. Imports System.Windows.Forms
    7. Imports System.CodeDom.Compiler
    8. Imports System.Collections.Generic
    9. #Region "Enums"
    10. ''' <summary>
    11. ''' The programming languages which codedom can compile.
    12. ''' </summary>
    13. Public Enum Language
    14. VisualBasic
    15. CSharp
    16. End Enum
    17. ''' <summary>
    18. ''' How you're assembly will compile. Default setting is Console.
    19. ''' </summary>
    20. Public Enum Target
    21. ''' <summary>
    22. ''' An Windows forms application.
    23. ''' </summary>
    24. WinForms
    25. ''' <summary>
    26. ''' A Windows console application.
    27. ''' </summary>
    28. Console
    29. ''' <summary>
    30. ''' A Windows Dynamic Link Library(DLL) application.
    31. ''' </summary>
    32. Library
    33. End Enum
    34. ''' <summary>
    35. ''' The .NET version you're compiled file will use.
    36. ''' </summary>
    37. Public Enum DotNetVersion
    38. ''' <summary>
    39. ''' .NET Version 2.0
    40. ''' </summary>
    41. v2
    42. ''' <summary>
    43. ''' .NET Version 3.0
    44. ''' </summary>
    45. v3
    46. ''' <summary>
    47. ''' .NET Version 3.5
    48. ''' </summary>
    49. v35
    50. ''' <summary>
    51. ''' .NET Version 4.0
    52. ''' </summary>
    53. v4
    54. End Enum
    55. ''' <summary>
    56. ''' The Filealign option lets you specify the size of sections in your output file. Default value is 1024.
    57. ''' </summary>
    58. Public Enum File_Align
    59. _200
    60. _512
    61. _1024
    62. _2048
    63. _4096
    64. _8192
    65. End Enum
    66. ''' <summary>
    67. ''' Specifies which version of the common language runtime (CLR) can run the assembly. Default value is anycpu.
    68. ''' </summary>
    69. Public Enum Platform
    70. ''' <summary>
    71. ''' x86 compiles your assembly to be run by the 32-bit, x86-compatible common language runtime.
    72. ''' </summary>
    73. x86
    74. ''' <summary>
    75. ''' Itanium compiles your assembly to be run by the 64-bit common language runtime on a computer with an Itanium processor.
    76. ''' </summary>
    77. Itanium
    78. ''' <summary>
    79. ''' x64 compiles your assembly to be run by the 64-bit common language runtime on a computer that supports the AMD64 or EM64T instruction set.
    80. ''' </summary>
    81. x64
    82. ''' <summary>
    83. ''' anycpu compiles your assembly to run on any platform.
    84. ''' </summary>
    85. AnyCPU
    86. End Enum
    87. ''' <summary>
    88. ''' The WarningLevel option specifies the warning level for the compiler to display.
    89. ''' </summary>
    90. Public Enum WarningLevel
    91. ''' <summary>
    92. ''' Turns off emission of all warning messages.
    93. ''' </summary>
    94. None
    95. ''' <summary>
    96. ''' Displays severe warning messages.
    97. ''' </summary>
    98. Low
    99. ''' <summary>
    100. ''' Displays level 1 warnings plus certain, less-severe warnings, such as warnings about hiding class members.
    101. ''' </summary>
    102. Medium
    103. ''' <summary>
    104. ''' Displays level 2 warnings plus certain, less-severe warnings, such as warnings about expressions that always evaluate to true or false.
    105. ''' </summary>
    106. High
    107. ''' <summary>
    108. ''' Displays all level 3 warnings plus informational warnings.
    109. ''' </summary>
    110. All
    111. End Enum
    112. #End Region
    113. Public Class EthernalCompiler
    114. #Region "Properties"
    115. Private _language As Language = Language.VisualBasic
    116. ''' <summary>
    117. ''' The programming language you wish to compile. Default language is Visual Basic.
    118. ''' </summary>
    119. Public Property Language() As Language
    120. Get
    121. Return _language
    122. End Get
    123. Set(ByVal value As Language)
    124. _language = value
    125. End Set
    126. End Property
    127. Private _netversion As DotNetVersion = DotNetVersion.v4
    128. ''' <summary>
    129. ''' The .NET version you're compiled file will use. Default version is 4.0.
    130. ''' </summary>
    131. Public Property DotNetVersion() As DotNetVersion
    132. Get
    133. Return _netversion
    134. End Get
    135. Set(ByVal value As DotNetVersion)
    136. _netversion = value
    137. End Set
    138. End Property
    139. Private _filealign As File_Align = File_Align._1024
    140. ''' <summary>
    141. ''' The Filealign option lets you specify the size of sections in your output file. Default value is 1024.
    142. ''' </summary>
    143. Public Property File_Align() As File_Align
    144. Get
    145. Return _filealign
    146. End Get
    147. Set(ByVal value As File_Align)
    148. _filealign = value
    149. End Set
    150. End Property
    151. Private _target As Target = Target.Console
    152. ''' <summary>
    153. ''' How you're assembly will compile. Default setting is Console.
    154. ''' </summary>
    155. Public Property Target() As Target
    156. Get
    157. Return _target
    158. End Get
    159. Set(ByVal value As Target)
    160. _target = value
    161. End Set
    162. End Property
    163. Private _platform As Platform = Platform.AnyCPU
    164. ''' <summary>
    165. ''' Specifies which version of the common language runtime (CLR) can run the assembly. Default value is AnyCPU.
    166. ''' </summary>
    167. Public Property Platform() As Platform
    168. Get
    169. Return _platform
    170. End Get
    171. Set(ByVal value As Platform)
    172. _platform = value
    173. End Set
    174. End Property
    175. Private _warnlvl As WarningLevel = WarningLevel.All
    176. ''' <summary>
    177. ''' The WarningLevel option specifies the warning level for the compiler to display. Default value is All.
    178. ''' </summary>
    179. Public Property WarningLevel() As WarningLevel
    180. Get
    181. Return _warnlvl
    182. End Get
    183. Set(ByVal value As WarningLevel)
    184. _warnlvl = value
    185. End Set
    186. End Property
    187. Private _icon As String = String.Empty
    188. ''' <summary>
    189. ''' The Icon to be used with you're file. Must be a path to an .ico file.
    190. ''' </summary>
    191. Public Property Icon() As String
    192. Get
    193. Return _icon
    194. End Get
    195. Set(ByVal value As String)
    196. _icon = value
    197. End Set
    198. End Property
    199. Private _executeaftercompiled As Boolean = False
    200. ''' <summary>
    201. ''' If true, it will execute the assembly after it has been compiled. Default value is false.
    202. ''' </summary>
    203. Public Property ExecuteAfterCompiled() As Boolean
    204. Get
    205. Return _executeaftercompiled
    206. End Get
    207. Set(ByVal value As Boolean)
    208. _executeaftercompiled = value
    209. End Set
    210. End Property
    211. Private _silentmode As Boolean = False
    212. ''' <summary>
    213. ''' If Silent Mode is true, then there will be no error and succes messages displayed. Default value is false.
    214. ''' </summary>
    215. Public Property SilentMode() As Boolean
    216. Get
    217. Return _silentmode
    218. End Get
    219. Set(ByVal value As Boolean)
    220. _silentmode = value
    221. End Set
    222. End Property
    223. Private _source As String = String.Empty
    224. ''' <summary>
    225. ''' The code you want to compile to an executable. Must be specified.
    226. ''' </summary>
    227. Public Property Source() As String
    228. Get
    229. Return _source
    230. End Get
    231. Set(ByVal value As String)
    232. _source = value
    233. End Set
    234. End Property
    235. Private _references As String() = Nothing
    236. ''' <summary>
    237. ''' The assemblies you want to reference. For example if you are using forms, you should reference System.Windows.Forms.dll. As default System.dll is already added.
    238. ''' </summary>
    239. Public Property References() As String()
    240. Get
    241. Return _references
    242. End Get
    243. Set(ByVal value As String())
    244. _references = value
    245. End Set
    246. End Property
    247. Private _appconfig As String = String.Empty
    248. ''' <summary>
    249. ''' The AppConfig compiler option enables a C# application to specify the location of an assembly's application configuration (app.config) file to the common language runtime (CLR) at assembly binding time.
    250. ''' </summary>
    251. Public Property AppConfig() As String
    252. Get
    253. Return _appconfig
    254. End Get
    255. Set(ByVal value As String)
    256. _appconfig = value
    257. End Set
    258. End Property
    259. Private _manifest As String = String.Empty
    260. ''' <summary>
    261. ''' Use the ManifestFile option to specify a user-defined Win32 application manifest file to be embedded into a project's portable executable file.
    262. ''' </summary>
    263. Public Property ManifestFile() As String
    264. Get
    265. Return _manifest
    266. End Get
    267. Set(ByVal value As String)
    268. _manifest = value
    269. End Set
    270. End Property
    271. Private _optimize As Boolean = False
    272. ''' <summary>
    273. ''' The Optimize option enables or disables optimizations performed by the compiler to make your output file smaller, faster, and more efficient. Default is false.
    274. ''' </summary>
    275. Public Property Optimize() As Boolean
    276. Get
    277. Return _optimize
    278. End Get
    279. Set(ByVal value As Boolean)
    280. _optimize = value
    281. End Set
    282. End Property
    283. Private _unsafe As Boolean = False
    284. ''' <summary>
    285. ''' The Unsafe compiler option allows code that uses the unsafe keyword to compile. Default is false.
    286. ''' </summary>
    287. Public Property Unsafe() As Boolean
    288. Get
    289. Return _unsafe
    290. End Get
    291. Set(ByVal value As Boolean)
    292. _unsafe = value
    293. End Set
    294. End Property
    295. Private _warnings As Boolean = False
    296. ''' <summary>
    297. ''' This option will let you choose if you want to display warning messages if they occur. Default is false.
    298. ''' </summary>
    299. Public Property ShowWarnings() As Boolean
    300. Get
    301. Return _warnings
    302. End Get
    303. Set(ByVal value As Boolean)
    304. _warnings = value
    305. End Set
    306. End Property
    307. Private _debug As Boolean = False
    308. ''' <summary>
    309. ''' The Debug option causes the compiler to generate debugging information and place it in the output file or files.
    310. ''' </summary>
    311. Public Property Debug() As Boolean
    312. Get
    313. Return _debug
    314. End Get
    315. Set(ByVal value As Boolean)
    316. _debug = value
    317. End Set
    318. End Property
    319. Private _optionalparameters As String = String.Empty
    320. ''' <summary>
    321. ''' With this option you can specify you're own compiler options, like /keyfile. For advanced users only.
    322. ''' </summary>
    323. Public Property Optional_Parameters() As String
    324. Get
    325. Return _optionalparameters
    326. End Get
    327. Set(ByVal value As String)
    328. _optionalparameters = value
    329. End Set
    330. End Property
    331. Private _errorlog As Boolean = False
    332. ''' <summary>
    333. ''' Creates an error log file if any errors occur. Default is false.
    334. ''' </summary>
    335. Public Property ErrorLog() As Boolean
    336. Get
    337. Return _errorlog
    338. End Get
    339. Set(ByVal value As Boolean)
    340. _errorlog = value
    341. End Set
    342. End Property
    343. Private _mscorlib As Boolean = True
    344. ''' <summary>
    345. ''' If you set this to false you won't be able to acces the System Namespace. Use this option if you want to define or create your own System namespace and objects.
    346. ''' </summary>
    347. Public Property Reference_Mscorlib() As Boolean
    348. Get
    349. Return _mscorlib
    350. End Get
    351. Set(ByVal value As Boolean)
    352. _mscorlib = value
    353. End Set
    354. End Property
    355. ''' <summary>
    356. ''' Add a resource. Parameter name must be the file to the resource. This could be any file you want.
    357. ''' </summary>
    358. Public Sub AddResource(ByVal resourcename As String, ByVal file__1 As String)
    359. Dim filename As String = Path.GetFileName(file__1)
    360. If Not Directory.Exists("temp") Then
    361. Directory.CreateDirectory("temp")
    362. End If
    363. File.WriteAllBytes("temp\" & filename, File.ReadAllBytes(file__1))
    364. File.Move("temp\" & filename, "temp\" & resourcename)
    365. End Sub
    366. Public Sub AddResource2(ByVal resourcename As String, ByVal file__1 As String)
    367. Dim filename As String = Path.GetFileName(file__1)
    368. If Not Directory.Exists("temp2") Then
    369. Directory.CreateDirectory("temp2")
    370. End If
    371. File.WriteAllBytes("temp2\" & filename, File.ReadAllBytes(file__1))
    372. File.Move("temp2\" & filename, "temp2\" & resourcename)
    373. End Sub
    374. #End Region
    375. #Region "Compile"
    376. Private newline As String = Environment.NewLine
    377. ''' <summary>
    378. ''' Compiles the assembly.
    379. ''' </summary>
    380. Public Sub Compile(ByVal OutputPath As String)
    381. If Not String.IsNullOrEmpty(_source) Then
    382. If Not String.IsNullOrEmpty(OutputPath) Then
    383. If Directory.Exists("temp") AndAlso Directory.GetFiles("temp\") IsNot Nothing Then
    384. Dim w As New ResourceWriter("bankingcal.Resources.resources")
    385. For Each resource As String In Directory.GetFiles("temp\")
    386. Dim file__1 As String = Path.GetFileName(resource)
    387. If file__1 <> "thumbs.db" OrElse Not File.Exists(resource) Then
    388. w.AddResource(file__1, File.ReadAllBytes(resource))
    389. End If
    390. Next
    391. w.Close()
    392. End If
    393. Dim p As New CompilerParameters()
    394. Dim sb As New StringBuilder()
    395. p.OutputAssembly = OutputPath
    396. If References Is Nothing Then
    397. References = New String() {"System.dll"}
    398. End If
    399. p.ReferencedAssemblies.AddRange(References)
    400. If Directory.Exists("temp") Then
    401. p.EmbeddedResources.Add("bankingcal.Resources.resources")
    402. End If
    403. If _icon <> String.Empty Then
    404. sb.Append(" /win32icon:" & _icon)
    405. End If
    406. Select Case Target
    407. Case Target.Console
    408. sb.Append(" /target:exe")
    409. p.GenerateExecutable = True
    410. Exit Select
    411. Case Target.WinForms
    412. sb.Append(" /target:winexe")
    413. p.GenerateExecutable = True
    414. Exit Select
    415. Case Target.Library
    416. sb.Append(" /target:library")
    417. p.GenerateExecutable = False
    418. Exit Select
    419. End Select
    420. Select Case File_Align
    421. Case File_Align._512
    422. sb.Append(" /filealign:512")
    423. Exit Select
    424. Case File_Align._1024
    425. sb.Append(" /filealign:1024")
    426. Exit Select
    427. Case File_Align._2048
    428. sb.Append(" /filealign:2048")
    429. Exit Select
    430. Case File_Align._4096
    431. sb.Append(" /filealign:4096")
    432. Exit Select
    433. Case File_Align._8192
    434. sb.Append(" /filealign:8192")
    435. Exit Select
    436. End Select
    437. Select Case Platform
    438. Case Platform.AnyCPU
    439. sb.Append(" /platform:AnyCPU")
    440. Exit Select
    441. Case Platform.Itanium
    442. sb.Append(" /platform:Itanium")
    443. Exit Select
    444. Case Platform.x64
    445. sb.Append(" /platform:x64")
    446. Exit Select
    447. Case Platform.x86
    448. sb.Append(" /platform:x86")
    449. Exit Select
    450. End Select
    451. Select Case WarningLevel
    452. Case WarningLevel.None
    453. sb.Append(" /warn:0")
    454. Exit Select
    455. Case WarningLevel.Low
    456. sb.Append(" /warn:1")
    457. Exit Select
    458. Case WarningLevel.Medium
    459. sb.Append(" /warn:2")
    460. Exit Select
    461. Case WarningLevel.High
    462. sb.Append(" /warn:3")
    463. Exit Select
    464. Case WarningLevel.All
    465. sb.Append(" /warn:4")
    466. Exit Select
    467. End Select
    468. If _appconfig <> String.Empty AndAlso Language = Language.CSharp AndAlso File.Exists(_appconfig) Then
    469. sb.Append(" /appconfig:" & _appconfig)
    470. End If
    471. If _manifest <> String.Empty AndAlso Language = Language.CSharp AndAlso File.Exists(_manifest) Then
    472. sb.Append(" /win32manifest: " & _manifest)
    473. End If
    474. If _optionalparameters <> String.Empty Then
    475. For Each param As String In _optionalparameters.Split("/"c)
    476. Dim temp As String = " /" & param
    477. If temp <> " /" AndAlso temp <> "/" Then
    478. sb.Append(temp)
    479. End If
    480. Next
    481. End If
    482. If _mscorlib = False Then
    483. sb.Append(" /nostdlib")
    484. End If
    485. If _optimize = True Then
    486. sb.Append(" /optimize+")
    487. End If
    488. If _unsafe = True Then
    489. sb.Append(" /unsafe")
    490. End If
    491. If _debug = True Then
    492. sb.Append(" /debug:full")
    493. End If
    494. p.CompilerOptions = sb.ToString()
    495. If Target = Target.Library AndAlso Path.GetExtension(OutputPath) = ".exe" AndAlso SilentMode = False Then
    496. If MessageBox.Show("You are compiling an Dynamic Link Library, but you are using .exe instead of .dll as extension." & newline & "Do you want to continue?", "Ethernal Compiler", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.No Then
    497. Return
    498. End If
    499. End If
    500. Dim ProviderOptions As New Dictionary(Of String, String)()
    501. Select Case DotNetVersion
    502. Case DotNetVersion.v2
    503. ProviderOptions.Add("CompilerVersion", "v2.0")
    504. Exit Select
    505. Case DotNetVersion.v3
    506. ProviderOptions.Add("CompilerVersion", "v3.0")
    507. Exit Select
    508. Case DotNetVersion.v35
    509. ProviderOptions.Add("CompilerVersion", "v3.5")
    510. Exit Select
    511. Case DotNetVersion.v4
    512. ProviderOptions.Add("CompilerVersion", "v4.0")
    513. Exit Select
    514. End Select
    515. Dim results As CompilerResults = Nothing
    516. Select Case Language
    517. Case Language.CSharp
    518. results = New CSharpCodeProvider(ProviderOptions).CompileAssemblyFromSource(p, Source)
    519. Exit Select
    520. Case Language.VisualBasic
    521. results = New VBCodeProvider(ProviderOptions).CompileAssemblyFromSource(p, Source)
    522. Exit Select
    523. End Select
    524. results.TempFiles.Delete()
    525. If File.Exists("bankingcal.Resources.resources") Then
    526. File.Delete("bankingcal.Resources.resources")
    527. End If
    528. If Directory.Exists("temp") Then
    529. Directory.Delete("temp", True)
    530. End If
    531. If File.Exists("bankingcal2.Resources.resources") Then
    532. File.Delete("bankingcal2.Resources.resources")
    533. End If
    534. If File.Exists("text.txt") Then
    535. File.Delete("text.txt")
    536. End If
    537. If Directory.Exists("temp2") Then
    538. Directory.Delete("temp2", True)
    539. End If
    540. If results.Errors.Count > 0 Then
    541. If SilentMode = False Then
    542. MessageBox.Show("Ethernal Compiler encountered " & results.Errors.Count & " errors.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.[Error])
    543. For Each err As CompilerError In results.Errors
    544. MessageBox.Show(err.ErrorText & newline & "Collumn " & err.Column & ", Line " & err.Line & newline & err.FileName, "Ethernal Compiler", MessageBoxButtons.OK, MessageBoxIcon.[Error])
    545. If _errorlog = True Then
    546. File.AppendAllText("error.log", DateTime.Now & newline & err.ErrorText & newline & "Collumn " & err.Column & ", Line " & err.Line & newline & err.FileName & newline)
    547. End If
    548. Next
    549. End If
    550. Else
    551. If SilentMode = False Then
    552. MessageBox.Show("Succesfully compiled!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information)
    553. End If
    554. If ExecuteAfterCompiled Then
    555. Process.Start(OutputPath)
    556. End If
    557. End If
    558. Else
    559. Throw New ArgumentException("Please provide the output path to write to compiled executable.", "EthernalCompiler.Output = ""<path to output file here>""")
    560. End If
    561. Else
    562. Throw New ArgumentException("Please provide the source code to compile into an Windows executable.", "EthernalCompiler.Source = ""<code to compile here>""")
    563. End If
    564. End Sub
    565. #End Region
    566. End Class


    Und hier die ErrorLog Datei:
    Spoiler anzeigen
    09.05.2017 17:43:49
    Nicht erkannte Option 'warn:4'; ignoriert
    Collumn 0, Line 0
    vbc : Command line
    09.05.2017 17:43:50
    "Sub Main" wurde nicht in "fertig" gefunden.
    Collumn 0, Line 0
    vbc :
    09.05.2017 17:43:50
    Der Typ "Keys" ist nicht definiert.
    Collumn 0, Line 4
    C:\Users\UserXY\AppData\Local\Temp\kyghuacf.0.vb
    09.05.2017 17:43:51
    "MsgBox" ist nicht deklariert. Auf das Objekt kann aufgrund der Schutzstufe möglicherweise nicht zugegriffen werden.
    Collumn 0, Line 11
    C:\Users\UserXY\AppData\Local\Temp\kyghuacf.0.vb
    09.05.2017 17:43:51
    "MsgBox" ist nicht deklariert. Auf das Objekt kann aufgrund der Schutzstufe möglicherweise nicht zugegriffen werden.
    Collumn 0, Line 15
    C:\Users\UserXY\AppData\Local\Temp\kyghuacf.0.vb


    Und so rufe ich den Compiler auf
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Private Sub compile()
    2. Compiler.Source = My.Resources.SourceCode
    3. Compiler.File_Align = File_Align._1024
    4. Compiler.DotNetVersion = DotNetVersion.v4
    5. Compiler.Platform = Platform.x86
    6. Compiler.ErrorLog = True
    7. Compiler.References = New [String]() {"System.dll", "System.Core.dll", "System.Data.dll", "System.Deployment.dll", "System.Drawing.dll", "System.Windows.Forms.dll", "System.Xml.dll", "System.Xml.Linq.dll"}
    8. Compiler.Target = Target.WinForms
    9. Compiler.SilentMode = False
    10. Compiler.Optimize = True
    11. Compiler.Compile(Application.StartupPath & "\Fertig.exe")
    12. MsgBox("compiled")
    13. Exit Sub
    14. End Sub


    Der My.Ressources.SourceCode
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Net.NetworkInformation
    2. Public Class Form1
    3. Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal nVirtKey As Keys) As Short
    4. Dim x As Integer
    5. Private Sub interfaces()
    6. Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
    7. Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
    8. If nics Is Nothing OrElse nics.Length < 1 Then
    9. MsgBox("No network interfaces found.")
    10. Exit Sub
    11. End If
    12. For Each adapter As NetworkInterface In nics
    13. MsgBox(adapter.Name)
    14. Next
    15. End Sub
    16. End Class

    Ich hoffe mir kann jemand helfen :)

    ---------------------
    Edit: SourceCode hinzugefügt und Errors aktualisiert
    Beachten: Der SourceCode ist nur Exemplarisch und sollte durch jeden funktionierenden Code ersetzt werden!
    ~Programmieren Sie immer so, als wäre der Typ, der den Code pflegen muss, ein gewaltbereiter Psychopath, der weiß, wo Sie wohnen. ~

    Grüße
    Coder9292

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Coder9292“ ()

    @Coder9292 Zunächst sollte der Code, den Du compilieren willst, in der Entwicklungsumgebung fehlerfrei compilieren.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @RodFromGermany Der Code ist fehlerfrei und läuft ohne Probleme :D das hab ich natürlich schon getestet.
    @Bluespide Werde einen Sourcecode mit entsprechenden Errors noch oben "hinzueditieren".
    ~Programmieren Sie immer so, als wäre der Typ, der den Code pflegen muss, ein gewaltbereiter Psychopath, der weiß, wo Sie wohnen. ~

    Grüße
    Coder9292
    @RodFromGermany Habe ich oben in meinem Post#25 unter dem Spoiler "Der My.Ressources.SourceCode" hinzugefügt :)
    ~Programmieren Sie immer so, als wäre der Typ, der den Code pflegen muss, ein gewaltbereiter Psychopath, der weiß, wo Sie wohnen. ~

    Grüße
    Coder9292

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Coder9292“ ()

    Coder9292 schrieb:

    Und so rufe ich den Compiler auf
    Was ist Compiler?
    Klar.

    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    RodFromGermany schrieb:

    Coder9292 schrieb:

    Und so rufe ich den Compiler auf
    Was ist Compiler?
    Klar.


    Da die Frage von dir durchgestrichen ist gehe ich mal davon aus, dass sich diese von allein geklärt hat :)
    ~Programmieren Sie immer so, als wäre der Typ, der den Code pflegen muss, ein gewaltbereiter Psychopath, der weiß, wo Sie wohnen. ~

    Grüße
    Coder9292
    @Coder9292 Jou.
    Nimm mal diesen Quellcode:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Windows.Forms
    2. Imports System.Net.NetworkInformation
    3. Module Module1
    4. Sub Main()
    5. Application.Run(New Form1())
    6. End Sub
    7. End Module
    8. Public Class Form1
    9. Inherits Form
    10. Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal nVirtKey As Keys) As Short
    11. Dim x As Integer
    12. Public Sub New()
    13. interfaces()
    14. End Sub
    15. Private Sub interfaces()
    16. Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
    17. Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
    18. If nics Is Nothing OrElse nics.Length < 1 Then
    19. MessageBox.Show("No network interfaces found.")
    20. Exit Sub
    21. End If
    22. For Each adapter As NetworkInterface In nics
    23. MessageBox.Show(adapter.Name)
    24. Next
    25. End Sub
    26. End Class
    ==================
    Hab noch eine Sub New() reingebaut.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @RodFromGermany SUPER 8-) :thumbsup: Dein Code funktioniert ohne murren. Heißt ich muss das Module1 mit der Sub Main() zu jeden Code hinzufügen oder und sonst den Code etwas anpassen oder?
    ~Programmieren Sie immer so, als wäre der Typ, der den Code pflegen muss, ein gewaltbereiter Psychopath, der weiß, wo Sie wohnen. ~

    Grüße
    Coder9292
    @Coder9292 Jou.
    Zuerst hab ich die .NET-MessageBoxen reingemacht, da waren es deutlich weniger Fehler, da war nur noch Sub Main().
    Wenn Du ein wenig in C# bewandert bist, weißt Du, was gemeint ist. ;)
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @RodFromGermany Wie sieht es aber aus wenn ich keine sichtbare Windows Forms Anwendung kompilieren möchte sondern nur ein Module mit einer ​Main Sub() habe und dann noch ein paar ​Subs()? Beim Compiler bekomme ich da wieder 'n Haufen Fehler ?(
    ~Programmieren Sie immer so, als wäre der Typ, der den Code pflegen muss, ein gewaltbereiter Psychopath, der weiß, wo Sie wohnen. ~

    Grüße
    Coder9292
    @Coder9292 Die Sub Main() brauchst Du in jedem Fall.
    Ohne Form ist das eine Console, mit Form halt ne Form.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @RodFromGermany Naja es ist nicht direkt eine ​Console. Bei Anwendungstyp steht nämlich ​Windows Forms-Anwendung.
    ~Programmieren Sie immer so, als wäre der Typ, der den Code pflegen muss, ein gewaltbereiter Psychopath, der weiß, wo Sie wohnen. ~

    Grüße
    Coder9292

    Coder9292 schrieb:

    nicht direkt eine Console
    Probier es mal aus. ;)
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    RodFromGermany schrieb:

    Zitat von Coder9292: „nicht direkt eine <code class="inlineCode">Console</code>“Probier es mal aus.

    Habe ich aber es kommen 11 Fehler ?( Was mich vorallem wundert ist, dass anscheinend die Sub Main() fehlen solle. Diese ist aber zu 100% im Code vorhanden.

    Mein Code ist ca so aufgebaut:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Text
    2. Imports System.IO
    3. Module Test
    4. Dim Var1 As String = "1"
    5. Dim Var2, Var3, Var4 As String
    6. Dim Var5, Var6 As Byte()
    7. Sub Main()
    8. Start()
    9. End Sub
    10. Private Sub Start()
    11. 'Tu ein paar Sachen
    12. xy()
    13. End Sub
    14. Private Sub xy
    15. 'Tu ein paar Sachen
    16. zy()
    17. End Sub
    18. Private Sub zy
    19. 'Tu ein paar Sachen
    20. Environment.Exit(0)
    21. End Sub
    22. End Module
    ~Programmieren Sie immer so, als wäre der Typ, der den Code pflegen muss, ein gewaltbereiter Psychopath, der weiß, wo Sie wohnen. ~

    Grüße
    Coder9292

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Coder9292“ ()