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>