概要
生成するアプリケーション(アセンブル?)に
アプリケーションタイトルやバージョン番号などのメタ情報を含める
参考にした情報:
実行環境:
F# 2.0 Compiler build 4.0.40219.1
Windows7 Starter SP1
.NET Framework v4.0.30319(?) v4.5.51209(?)
##方法
アセンブリにメタ情報を含めるには属性を使う。
次の名前空間に必要な属性がだいたい揃っている。
open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
これらの属性はアセンブリ内の最上位のdo
バインディングに適用する必要がある。
[<assembly: AssemblyTitle("Application Title")>]
[<assembly: AssemblyDescription("Description")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("Company Name")>]
[<assembly: AssemblyProduct("Pruduct Name")>]
[<assembly: AssemblyCopyright("Copyright @ my name")>]
[<assembly: AssemblyTrademark("")>]
[<assembly: ComVisible(false)>]
[<assembly: Guid("00000000-0000-0000-0000-000000000000")>]
[<assembly: AssemblyVersion("1.0.0.0")>]
[<assembly: AssemblyFileVersion("1.0.0.0")>]
do
// code or ()
###例1(エントリポイント指定なし)
do
明示
// Example1-1.fs
// fsc.exe --target:exe --out:Example1-1.exe Example1-1.fs
open System.Reflection
[<assembly: AssemblyTitle("Application Title")>]
do
printfn "do it!"
do
省略
// Example1-2.fs
// fsc.exe --target:exe --out:Example1-2.exe Example1-2.fs
open System.Reflection
[<assembly: AssemblyTitle("Application Title")>]
printfn "do it!"
###例2(エントリポイント指定あり)
do
の明示が必須
// Example2.fs
// fsc.exe --target:exe --out:Example2.exe Example2.fs
open System.Reflection
[<assembly: AssemblyTitle("Application Title")>]
do
() // ()ではなく普通のdoバインディングと同じようにコード書いても問題はない
[<EntryPoint>]
let main args =
printfn "do it!"
0
###例3(別ファイルに分離) コンパイルコマンド
fsc.exe --target:exe --out:Foo.exe Bar.fs Foo.fs
Foo.fs
open Bar // Barモジュール内のコードを参照しない場合でもopenをしておかないと生成にBarの内容がリンクなされない
[<EntryPoint>]
let main args =
printfn "do it!"
0
Bar.fs
module Bar
open System.Reflection
[<assembly: AssemblyTitle("Application Title")>]
do
() // 外部モジュールとして読み込むのでここに書いたコードの実行タイミングは不明になる
// 上記のような外部モジュール内のトップレベルバインディングのうち次のようなコードは実行タイミングが微妙
// * 式結果の代入
// let hoge = "HOGE" + "hoge"
// let fuga = printfn "FUGA"
// * doバインディング
// do
// printfn "PIYO"
// * 行頭からのコード(doバインディングのdoの省略)
// printfn "Hage"
// など
// これらのコードは「式結果の代入」のコードが初めて参照されたタイミングで全て実行されるらしい(確証はない)
// たぶん、ちゃんと調べれば回避策が出てくるはず・・・?
###例4(ライブラリ(DLL)の生成)
do
の明示が必須
// Example4.fs
// fsc.exe --target:library --out:Example4.dll Example4.fs
module Example4 // モジュール名宣言省略するとファイル名のExample4がモジュール名に自動的に採用されるらしい
open System.Reflection
[<assembly: AssemblyTitle("Application Title")>]
do
() // ここにコードを書いてもたぶん 例3 と同じことになると思う
// ライブラリなので当然だが外部から参照するコードを書くだろうが、書かなくてもコンパイルは通る