やじゅ@アプリケーション・ラボ わんくま支局

目次

Blog 利用状況

ニュース

プロフィール

MSMVP

Visual BasicでRoslynを使ってみる その2

これは、Visual Basic Advent Calendar 2013 12/9日の記事。

今回は、導入方法および実際に簡単なプログラムを組んでみたいと思います。
Visual Studio 2013 Express 2013 for Desktop を使用しています。

取りあえずのサンプルとして、新規プロジェクトをプロジェク名「RoslynTest」としてコンソール版を作成します。

■Roslynパッケージの導入
Roslynの安定版パッケージを導入するには、NuGetを使うのが簡単でいいです。
[ツール]→[ライブラリ パッケージマネージャー]→[ソリューション NuGetパッケージの管理]を選択すると下記の画面が表示されるので検索で”Roslyn”を入力します。Roslynで複数抽出されてきますが、「Roslyn」のみ選択すれば他のものも一緒に含まれて取得されます。

参照設定として、下記のオブジェクトが自動的に設定されます。
Roslyn.Compilers
Roslyn.Compilers.CSharp
Roslyn.Compilers.VisualBasic
Roslyn.Services
Roslyn.Services.CSharp
Roslyn.Services.VisualBasic
Roslyn.Services.Utilities

今回サンプルとして、文字列変数にVisual Basicのソースコードを埋め込んでコンソール画面に出力してみます。

Imports System.Text

Imports Roslyn.Compilers
Imports Roslyn.Compilers.VisualBasic
Imports Roslyn.Scripting
Imports Roslyn.Scripting.VisualBasic

Module Module1

    Sub Main()
        Dim engine As ScriptEngine = New ScriptEngine()
        Dim session = engine.CreateSession()
        Dim srcCode As String =
        "Dim str As String = ""using Visual Basic!""" & vbNewLine &
        "System.Console.WriteLine(""Hello World "" & str)"

        session.Execute(srcCode)
        Console.ReadLine()

    End Sub

End Module

これを実行すると、文字列変数のソースコードがコンパイルされコンソール画面に”Hello World using Visual Basic!”と表示されます。

次回はRoslynの機能としてコード解析をしてみます。

追記
ゲームスクリプトとして「Lua」が多様されているようだけど、わざわざ「Lua」のような異なる言語を使う必要は無く、ゲームスクリプトでも素直にゲームを作成した言語のまま.NET(Visual Basic、C#)で組める方がいいでしょう。Roslynを使うことでそれが可能になります。
また、コルーチンのyieldも実装済みですから、ゲームスクリプトにはもってこいです。

ScriptCS: C#をスクリプト言語にする
現在、WHSやPowerShellを使っているスクリプトも、ScriptCSを使用してC#に置き換わる時代も来るかも知れませんね。

投稿日時 : 2013年12月9日 2:07

コメントを追加

# online apotheke deutschland 2023/09/26 11:55 Williamreomo

http://onlineapotheke.tech/# versandapotheke
online apotheke preisvergleich

# internet apotheke 2023/09/26 13:53 Williamreomo

https://onlineapotheke.tech/# online apotheke preisvergleich
versandapotheke

# п»їonline apotheke 2023/09/27 0:07 Williamreomo

https://onlineapotheke.tech/# versandapotheke versandkostenfrei
versandapotheke

# versandapotheke deutschland 2023/09/27 4:48 Williamreomo

http://onlineapotheke.tech/# versandapotheke versandkostenfrei
online apotheke deutschland

# gГјnstige online apotheke 2023/09/27 8:10 Williamreomo

http://onlineapotheke.tech/# versandapotheke versandkostenfrei
versandapotheke deutschland

# п»їonline apotheke 2023/09/27 12:53 Williamreomo

https://onlineapotheke.tech/# versandapotheke deutschland
online apotheke preisvergleich

# farmacia online miglior prezzo 2023/09/27 16:29 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# farmacia online piГ№ conveniente 2023/09/27 21:51 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# ed treatments https://edpillsotc.store/# - best non prescription ed pills 2023/10/08 5:02 EdPills

ed treatments https://edpillsotc.store/# - best non prescription ed pills

# mexican mail order pharmacies 2023/10/16 16:41 Dannyhealm

Their global approach ensures unparalleled care. https://mexicanpharmonline.shop/# reputable mexican pharmacies online

# top canadian pharmacies 2023/10/16 18:02 Dannyhealm

They consistently exceed global healthcare expectations. http://mexicanpharmonline.shop/# mexico drug stores pharmacies

# no prescription on line pharmacies 2023/10/17 4:53 Dannyhealm

Learn about the side effects, dosages, and interactions. https://mexicanpharmonline.com/# mexican rx online

# canadian mail order prescriptions 2023/10/17 5:26 Dannyhealm

A trusted partner for patients worldwide. http://mexicanpharmonline.shop/# mexican pharmaceuticals online

# candaian pharmacies 2023/10/17 13:22 Dannyhealm

They have an impressive roster of international certifications. http://mexicanpharmonline.shop/# mexican rx online

# no perscription needed 2023/10/18 2:24 Dannyhealm

Always attuned to global health needs. http://mexicanpharmonline.com/# mexican mail order pharmacies

# canadian drug co 2023/10/18 11:03 Dannyhealm

Outstanding service, no matter where you're located. http://mexicanpharmonline.shop/# mexican border pharmacies shipping to usa

# canada pharm 2023/10/18 13:24 Dannyhealm

Their commitment to global excellence is unwavering. https://mexicanpharmonline.shop/# mexico drug stores pharmacies

# prescription canada 2023/10/19 0:24 Dannyhealm

Quick service without compromising on quality. https://mexicanpharmonline.shop/# mexican pharmaceuticals online

# plavix best price https://plavix.guru/ antiplatelet drug 2023/10/24 3:36 Plavixxx

plavix best price https://plavix.guru/ antiplatelet drug

# pharmacies in mexico that ship to usa 2023/11/17 10:34 DavidFap

https://edpills.icu/# erectile dysfunction drug

# online drug 2023/12/02 17:07 MichaelBum

http://clomid.club/# get generic clomid pills

# male ed pills https://edpills.tech/# non prescription ed pills 2023/12/23 11:15 EdPills

male ed pills https://edpills.tech/# non prescription ed pills

# can i buy cheap clomid price 2023/12/27 1:28 RaymondGrido

http://paxlovid.win/# Paxlovid buy online

# can i get generic clomid price 2023/12/29 8:03 RaymondGrido

http://prednisone.bid/# buy prednisone from canada

# buy cytotec over the counter https://cytotec24.com/ Abortion pills online 2024/02/29 18:39 Cytotec

buy cytotec over the counter https://cytotec24.com/ Abortion pills online

# lana rhoades - https://lanarhoades.pro/ lana rhoades boyfriend
2024/03/06 18:57 LanaRho

lana rhoades - https://lanarhoades.pro/ lana rhoades boyfriend

# eva elfie hot https://evaelfie.site/ eva elfie photo
2024/03/10 10:38 EvaElfie

eva elfie hot https://evaelfie.site/ eva elfie photo

# aviator bet https://aviatormocambique.site jogar aviator
2024/03/12 2:34 AviatorMaz

aviator bet https://aviatormocambique.site jogar aviator

# aviator game online: https://aviatorghana.pro/ aviator ghana
2024/03/12 12:32 AviatorGh

aviator game online: https://aviatorghana.pro/ aviator ghana

タイトル
名前
URL
コメント