FsLex FsYacc微軟本身也提供了一個項目模板。但是這個項目模板是lex和yacc檔案均包含。我想只適用lex,但是如果每次使用命令列也覺得不夠方便,於是還是研究了一番MsBuild的使用。
使用msbuild hellp.fsproj /v:d 可以查看整個msbuild的流程,非常白盒。
hello.fsproj檔案:
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion="4.0"
DefaultTargets="MyBuild"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="FsLex" AssemblyFile="E:\Program Files (x86)\FSharpPowerPack-2.0.0.0\bin\FSharp.PowerPack.Build.Tasks.dll"/>
<UsingTask TaskName="Fsc" AssemblyFile="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\FSharp.Build.dll"/>
<PropertyGroup>
<AssemblyName>hello</AssemblyName>
<OutputPath>Bin\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="*.fs"/>
<Reference Include="FSharp.PowerPack"/>
<Reference Include="System" />
<Reference Include="System.Core" />
以下不需要寫,寫了編譯器會提示需要 -noframework 直接簡化掉乾脆不寫
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core" />
</ItemGroup>
<Target Name="MyBuild" >
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
具體還有那些屬性等,使用物件瀏覽器查看即可
兩個比較有用的路徑:能找DLL 和targets檔案,targets在不知道怎麼寫的時候很有用,模仿微軟寫法。
C:\Program Files (x86)\Microsoft F#\v4.0
E:\Program Files (x86)\FSharpPowerPack-2.0.0.0\bin
<FsLex
InputFile="Lexer.fsl"
OutputFile="Lexer.fs" <!-- 直接在proj檔案目錄產生Lexer.fs-->
OtherFlags="--unicode"
/>
<Fsc
Sources="@(Compile)"
OutputAssembly="$(OutputPath)$(AssemblyName).exe"
References ="@(Reference)"
/>
</Target>
<Target Name="Clean" >
<Delete Files="$(OutputPath)$(AssemblyName).exe" />
</Target>
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />
</Project>