9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CSharpZxScriptでbatファイルからの脱出

Last updated at Posted at 2021-09-01

はじめに

心地よく書けるC#スクリプトとしてCSharpZxScriptを作ってみました。
dotnet tool経由で簡単に導入出来ます。

image
image

心地よく書ける

C#でスクリプトが書ける物で公式のcsxがありますがVisualStudioでコード補完が効きにくかったり書きにくいです。
そこで内部でこっそり.csproj を生成したりします。
C#9.0のTop Level StatementとProcessXを組み合わせると中々良い感じに書けます。
デバッガーも繋げます。

動作環境

必要な環境は.NET5.0 (C#9.0 が必要なため) WindowsでもMacでもLinuxでも動きます。
CLIによる各種操作の実行
GUI操作での実行(Windowsのみ

導入方法

dotnet toolコマンドで導入を行います。

dotnet tool install --global CSharpZxScript

cszx コマンドが使えるようになります。
各種cszxコマンドは helpを見てください。
installをしてダブルクリックや右クリックメニューから動かせるようにします。

cszx install

消すときは cszx uninstall で消えます

使い方

.csファイルを右クリックしてEdit or Run します。
image

.cszxに拡張子を変えるとダブルクリックで実行出来るようになります。
ただし.cszxにしてしまうとコード補完が効かなくなり編集しにくいです

コマンドからの起動は拡張子を明示しないほうがおすすめです。
編集時は.cs、Fixするときに.cszxとやりやすいので。
cszxスクリプトからcszxスクリプトを呼び出す時の面倒回避にもなります。

cszx test

おわり

私のプロジェクトはCSharpZxScriptをインストールするbatファイル以外全て置き換えました。

本来の用途ではないんですが単純なアプリケーションをこいつで書くのが結構便利でした。
「FileServerとClientを両方Core.csproj参照してExe作っている」という状況があったのでスクリプト化するとスッキリしました。

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?