How can i get the version of the .NET Framework i am targeting, rather than the version of the .NET framework the app is currently running under?
For example, if the application targets .NET Framework 4.5, i would need to know that i am targeting .NET Framework 4.5.
For example, checking System.Environment.Version
:
4.0.30319.18502
4.0.30319.18502
So that doesn't work.
The real goal is to try to work around the lack of compiler defines in .NET.
To verify the change, on the menu bar, select Project > Properties to open your project Property Pages dialog box. In the dialog box, select the Configuration Properties > General property page. Verify that . NET Target Framework Version shows the new Framework version.
That's simple - check the TargetFrameworkAttribute:
var targetFrameworkAttribute = Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), false)
.SingleOrDefault();
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With