2007/11/08
EmEditor私のマクロその3 .vb .cs .jsのコンパイル実行
.NETアプリをFramework付属のコンパイラを使ってコンパイルし、できあがった実行ファイルexeを実行するというものです。これがまた便利でw *.vbか*.csか*.jsファイルを開いた状態で、コメント行に記述したコンパイラに渡すオプション(VB.NETなら'/r:System.Windows.Forms.Dll /t:winexeという行の/r:System.Windows.Forms.Dll /t:winexeという部分)を選択すると、そのコンパイラオプションをつけてコンパイルします。デフォルトだと/t:exeが渡されます。
'*.cs, *.vb, *.jsをコンパイルして実行 Set regEX = New RegExp regEx.Global = True regEX.IgnoreCase = True Set Fs = CreateObject("Scripting.FileSystemObject") Set WshShell = CreateObject("WScript.Shell") sCompilerDir = "C:\windows\Microsoft.NET\Framework\v2.0.50727\" sDefaultArguments = "/t:exe" 'winexe sSourcePath = Document.FullName sEXEPath = Fs.BuildPath(Fs.GetParentFolderName(sSourcePath),Fs.GetBaseName(sSourcePath) & ".exe") sExt = LCase(Fs.GetExtensionName(sSourcePath)) Document.Save sSourcePath 'ソース保存 Select Case sExt Case "vb" : sCompilerPath = sCompilerDir & "vbc.exe" Case "cs" : sCompilerPath = sCompilerDir & "csc.exe" Case "js" : sCompilerPath = sCompilerDir & "jsc.exe" Case Else : sCompilerPath = "" End Select Set sel = Document.Selection If sel.IsEmpty Then sArguments = sDefaultArguments Else regEx.Pattern = "\s?(\/[^\:]+\:\S+)\s?" If regEx.Test(sel.Text) Then For Each oMatch In regEx.Execute(sel.Text) sArguments = sArguments & oMatch.SubMatches(0) & " " Next Else sArguments = "" End If End If If sCompilerPath="" Then Alert sExt & "ファイルに対応するコンパイラがありません。" Else sCommandLine = "cmd.exe /k " & sCompilerPath & " " & _ "/out:" & """" & sEXEPath & """" & " " & sArguments & " " & _ """" & sSourcePath & """" WshShell.Run sCommandLine ,,True 'コンパイル実行 If Fs.FileExists(sEXEPath) Then WshShell.Run sEXEPath,,True 'コンパイルしたファイルを実行 Else Alert "コンパイルに失敗したようです。" End If End If元記事:http://blogs.wankuma.com/mutaguchi/archive/2007/11/08/106978.aspx
プライバシーポリシー