People have been embedding and executing VBScript within batch files for a long time. But all the published solutions that I have seen (at the time this question was ori
I don't how much exactly the VB.NET counts for VBScript but it is definitely VisualBasic code with some C# flavours.
With the version of msbuild
there's a thing called an inline tasks that allows you to load a .net code into memory and execute it. And this can be embedded into a batch file with the a similar manner that used with wsf:
it verbose indeed though xml syntax allows almost everything to be put in one line if somebody wants (but I thing for educational reasons is better this example to be left like that). The batch code cannot contain --
so for robustness this part can be put in a CDATA also.
Other way to embed VB.NET into batch without temp files is with the help of powershell and its type definition cmdlet:
<# : batch portion
@echo off & setlocal
set "CMD_ARGS=%~1"
powershell -noprofile "iex (${%~f0} | out-string)"
goto :EOF
: end batch / begin powershell #>
param($psArg1 = $env:psArg1)
$VB = @"
Imports System
namespace VB
Public Class VB
Public Shared Sub Print()
Console.WriteLine("PRINTED BY VB")
End Sub
End Class
End Namespace
"@
Add-Type -TypeDefinition $VB -Language VisualBasic
[VB.VB]::Print()