使用MSBuild編譯FsLex項目

來源:互聯網
上載者:User

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>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.