Eric Dand
Eric Dand

Reputation: 1210

Defining preprocessor symbols in a FAKE MSBuild task

Is there a way to define a preprocessor symbol in an MSBuild task in FAKE?

For example, if my code has something like this in it:

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

Then I want to define the symbol LOCAL at build-time, in my F# build script.

Upvotes: 2

Views: 435

Answers (1)

Eric Dand
Eric Dand

Reputation: 1210

Thanks to Ron Beyer (see comments) for pointing me in the right direction. The answer was indeed to use the DefineConstants project property. In a typical FAKE MSBuild task, this would look like this:

// 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

Upvotes: 5

Related Questions