What prevents you from using an ordinary /define
?
csc /define:NET45 /optimize /out:MyProgram.exe *.cs
with
using System;
public class Test
{
public static void Main()
{
#if (NET45)
Console.WriteLine("NET45 targeted");
#else
Console.WriteLine("NET45 not targeted");
#endif
}
}