【问题标题】:Defining preprocessor symbols in a FAKE MSBuild task在 FAKE MSBuild 任务中定义预处理器符号
【发布时间】:2015-05-20 01:40:30
【问题描述】:

有没有办法在 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

【问题讨论】:

  • 我想这取决于您使用的构建脚本类型。您可以使用/define 命令行参数或DefineConstants 项目属性。见msdn.microsoft.com/en-us/library/bb629394.aspx
  • 我使用FAKE 作为构建脚本引擎。它有一些内置的 MSBuild 相关任务,但似乎没有一个可以选择使用 /define 参数。

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


【解决方案1】:

感谢 Ron Beyer(参见 cmets)为我指明了正确的方向。答案确实是使用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

【讨论】:

猜你喜欢
  • 2010-09-26
  • 2021-01-17
  • 2023-04-04
  • 1970-01-01
  • 2016-03-04
  • 1970-01-01
  • 2010-10-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多