都内で働くSEの技術的なひとりごと / Technical soliloquy of System Engineer working in Tokyo

都内でサラリーマンやってます。SQL Server を中心とした (2023年からは Azure も。) マイクロソフト系(たまに、OSS系などマイクロソフト以外の技術も...)の技術的なことについて書いています。日々の仕事の中で、気になったことを技術要素関係なく気まぐれに選んでいるので記事内容は開発言語、インフラ等ばらばらです。なお、当ブログで発信、発言は私個人のものであり、所属する組織、企業、団体等とは何のかかわりもございません。ブログの内容もきちんと検証して使用してください。英語の勉強のため、英語の

.NET アプリケーションの高速化について探し始めてみた - その1 - ( アセンブリの圧縮 )

 今月・来月は、.NET アプリケーションの高速化について色々調査したいと思います。コードの最適化、NGEN等といった一般的な高速化手法があります。今回はネットで調べ物していた時に見つけたものを少し紹介したいと思います。RPX ( Rugland Packer for ( .Net ) eXecutables ) という .NET アプリケーション・アセンブリの圧縮ツールです。ここからダウンロード可能です。

Rugland Packer for (.Net) eXecutables 1.3

 

Powered by NDependCompress .NET executables and pack multiple assemblies into a single executable bundle. It requires no additional external assembly or library to decompress so you get really good compression with only about a 7KB overhead. It's developed in C#

Compress .Net Executables.

  • Compress your .Net assembly for faster download.
  • High ZIP compression with no unpack library overhead.
  • Bundle multiple assemblies into a single distribution.
  • Works for Windows Forms and Console Applications.
  • Create a toolkit application that is a composite of multiple assemblies accessible via a menu.
  • Persist or explicitly define your assembly info from the original assembly or from a source file.
  • Persist or add a new icon to your packed executable.

  シェアウェアなどに向いていそうですね。昔、Delphi とか参照している 複数の dll などをまとめて exe にできましたね。それに似ている思いました。シェアウェアといえば Delphi でしたねー。昔話はさておき、ドキュメントを参照しましょう。 

 単純に EXE を圧縮したり、

This demo creates compressed assembly from a single windows forms executable.

"Rpx.exe" "Demo1\RpxDemo.exe" /o "Demo1\Compressed\RpxDemo1_Comp1.exe" /v Normal

 

  EXE とアセンブリを一つの EXE に統合したり、

This demo creates compressed assembly from a single console executable and a single supporting .dll assembly.

"Rpx.exe" "Demo2\RpxDemo2.exe" "Demo2\DemoLib1.dll" /o "Demo2\Compressed\RpxDemo2_Comp1.exe" /v Normal

できるようです。

 

 実際に Rpx.exe の動作を試してみましょう。ソースコードここからダウンロードできます。Stable 4.0 フォルダ配下のソリューションファイルを Visual Studio で開いてください。参照設定等を修正する必要があります。Ionic.Zip.Reduced、Rug.Cmd を NuGet で再取得してください。修正後、ソリューションをフルビルドします。

 Stable 4.0 / Demos フォルダ配下の Test.bat or Test.ps ファイルを実行します。正常に実行されると下記のようになります。Rpx コマンドで圧縮された、exe が起動されます。※下記はbatを実行しました。

f:id:koogucc11:20130818222849p:plain

 うーん。何故か最終のファイルサイズが大きくなってしまっています。本当は小さくなるのでしょう。次はアセンブリと結合してみます。

f:id:koogucc11:20130818223300p:plain

 うまくいきました。きちんと exe と アセンブリが結合されて一つの exe が生成されました。次は、AssemblyInfo.cs と exe を結合して ToolDemo.exe が生成されました。

f:id:koogucc11:20130818223727p:plain

この手のツールは他にも色々ありそうですね。この手のツールは、万能なツールが中々なさそうな感じがします。