在FAKE MSBuild任务中定义预处理程序符号

时间:2015-05-20 01:40:31

标签: c# build msbuild c-preprocessor f#-fake

有没有办法在FAKE中的MSBuild任务中定义预处理器符号?

例如,如果我的代码中包含类似的内容:

#if LOCAL
private static string databaseUrl = "http://localhost/myDbFile.sqlite";
#else
private static string databaseUrl = "http://www.website.com/myPublicDbFile.sqlite";
#endif

然后我想在构建时在我的F#构建脚本中定义符号LOCAL

1 个答案:

答案 0 :(得分:5)

感谢Ron Beyer(见评论)指出我正确的方向。答案确实是使用DefineConstants项目属性。在典型的FAKE MSBuild任务中,这将如下所示:

// Build a special version with the "SPECIAL" directive defined.
MSBuild
    null 
    "publish" 
    ([
        ("Configuration", "Release"); 
        ("Verbosity", "minimal");
        ("ProductName", "My Project (Special)");
        ("InstallUrl", "http://www.example.com/software/MyProjectSpecial/");
        ("DefineConstants", "SPECIAL")
    ])
    ["../MyProject/MyProject/MyProject.csproj"] 
        |> ignore