Question

I have some web config app settings like page urls that change based on development environment and production environment.

I'd like the app settings to be embedded in some aspx files somehow during compile time without having to call the app settings from code to make sure they are using the correct page urls.

Is this possible to do?

Was it helpful?

Solution

Yes, you can use the compiler options to define your flags as:

<system.codedom>
<compilers>
  <compiler language="c#;cs;csharp" extension=".cs"   
   compilerOptions="/D:FirstDefine,SecondDefine" 
            type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
    <providerOption name="CompilerVersion" value="v4.0" />
    <providerOption name="WarnAsError" value="false" />
  </compiler>
</compilers>
</system.codedom>

Then on your code you can use

#if FirstDefine
     // ... your code 
#endif

MSDN Reference

C# Compiler Options Listed Alphabetically

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top