forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameworkUtils.cs
More file actions
34 lines (32 loc) · 1.11 KB
/
FrameworkUtils.cs
File metadata and controls
34 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ScriptCs
{
public static class FrameworkUtils
{
private static string _frameworkName;
public static string FrameworkName
{
get
{
if (_frameworkName == null)
{
// in order to handle the weird behavior of old nuget packages
// with NET Standard 2.0, we'll use the entry assembly if possible
var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
//Thanks to Dave Glick for this code contribution
var frameworkName = assembly.GetCustomAttributes(true)
.OfType<System.Runtime.Versioning.TargetFrameworkAttribute>()
.Select(x => x.FrameworkName)
.FirstOrDefault();
_frameworkName = frameworkName;
}
return _frameworkName;
}
}
}
}