Exemple #1
0
        static string GetVersion( )
        {
            try
            {
                // see: https://stackoverflow.com/questions/19096841

                System.Runtime.Versioning.TargetFrameworkAttribute target_framework_attribute =
                    (System.Runtime.Versioning.TargetFrameworkAttribute)
                    Assembly
                    .GetExecutingAssembly( )
                    .GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), false)
                    .SingleOrDefault( );

                if (target_framework_attribute == null)
                {
                    return(null);
                }

                return(Regex.Match(target_framework_attribute.FrameworkName, @"\d+(\.\d+)*", RegexOptions.ExplicitCapture | RegexOptions.Compiled).Value);
            }
            catch (Exception exc)
            {
                _ = exc;
                if (Debugger.IsAttached)
                {
                    Debugger.Break( );
                }

                return(null);
            }
        }
 static void PrintTargetFramework()
 {
     Object[] ca = Assembly.GetEntryAssembly().GetCustomAttributes(false);
     foreach (var item in ca)
     {
         if (item.GetType().FullName == "System.Runtime.Versioning.TargetFrameworkAttribute")
         {
             System.Runtime.Versioning.TargetFrameworkAttribute t = (System.Runtime.Versioning.TargetFrameworkAttribute)item;
             Console.WriteLine("Current .NET Framework is: " + t.FrameworkDisplayName);
         }
     }
 }
Exemple #3
0
        // Main entry point for the console application
        static void Main(string[] args)
        {
            // Sample console application in C#
            System.Runtime.Versioning.TargetFrameworkAttribute targetFramework =
                (System.Runtime.Versioning.TargetFrameworkAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(
                    typeof(System.Runtime.Versioning.TargetFrameworkAttribute), false).SingleOrDefault();
            string msgWelcome = String.Format("### C# console application, targetting {0} ###", targetFramework.FrameworkDisplayName);
            Console.WriteLine(msgWelcome);
            Console.WriteLine();

            // Display some system information
            DisplaySystemInformation();

            // Display information about .NET versions installed
            DisplayDotNetInfo();

            // Show some information about this assembly
            DisplayAssemblyInfo();

            // Show information about another assembly
            DisplayOtherAssemblyInfo();

            // Show the arguments passed to this console application
            Console.WriteLine("# Check for arguments #");
            if (args.Length == 0)
                Console.WriteLine("  No arguments supplied...");
            else
            {
                // At least one argument supplied...
                Console.WriteLine("  Number of arguments passed: {0}", args.Length);

                // Attempt to convert the first parameter to an integer
                int firstArgAsInt;
                if (int.TryParse(args[0], out firstArgAsInt))
                    Console.WriteLine("  First argument is the integer \"{0}\"", firstArgAsInt);
                else
                    Console.WriteLine("  First argument is NOT an integer");

                // Now try to convert the first parameter as a floating point number
                float firstArgAsFloat;
                if (float.TryParse(args[0], out firstArgAsFloat))
                    Console.WriteLine("  First argument is the float \"{0:0.000}\"", firstArgAsFloat);
                else
                    Console.WriteLine("  First argument is NOT a float");
            }
            Console.WriteLine("");

            // Write a message over multiple lines
            string msgMultiLine = ("This message will..." + Environment.NewLine + "...span multiple lines" + Environment.NewLine);
            Console.WriteLine(msgMultiLine);

            // Check whether we have a debugger attached
            if (Debugger.IsAttached)
            {
                // Since there is a debugger attached, assume we are running from the IDE
                Console.WriteLine("Debugger is attached! Press any key to exit...");
            }
            else
            {
                // Assume we aren't running from the IDE
                Console.WriteLine("Debugger is NOT attached!");
            }

            //Console.WriteLine("Press any key to exit...");
            Console.ReadKey(false);
        }