forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
90 lines (83 loc) · 2.34 KB
/
Utils.cs
File metadata and controls
90 lines (83 loc) · 2.34 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// ReSharper disable once CheckNamespace
namespace System;
/// <summary>
/// 项目工具类
/// </summary>
public static partial class ProjectUtils
{
/// <summary>
/// 当前项目绝对路径
/// </summary>
public static readonly string ProjPath;
static ProjectUtils()
{
ProjPath = GetProjectPath();
// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
isCI = bool.TryParse(Environment.GetEnvironmentVariable("CI"), out var result) && result;
}
/// <summary>
/// 获取当前项目绝对路径(.sln文件所在目录)
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string GetProjectPath(string? path = null)
{
path ??=
#if NET46_OR_GREATER || NETCOREAPP
AppContext.BaseDirectory;
#else
AppDomain.CurrentDomain.BaseDirectory;
#endif
try
{
#pragma warning disable IDE0079 // 请删除不必要的忽略
#pragma warning disable SA1003 // Symbols should be spaced correctly
if (!
#pragma warning restore SA1003 // Symbols should be spaced correctly
#pragma warning restore IDE0079 // 请删除不必要的忽略
#if NET35
Directory.GetFiles
#else
Directory.EnumerateFiles
#endif
(path, "*.sln").Any())
{
var parent = Directory.GetParent(path);
if (parent == null)
return string.Empty;
return GetProjectPath(parent.FullName);
}
}
catch
{
return string.Empty;
}
return path;
}
#if !APP_HOST
#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter
/// <summary>
/// 当前目标框架 TFM
/// </summary>
public static readonly string tfm =
#pragma warning restore SA1307 // Accessible fields should begin with upper-case letter
$"net{Environment.Version.Major}.{Environment.Version.Minor}{tfm_}";
/// <summary>
/// 当前目标框架 TFM 后缀
/// </summary>
public const string tfm_ =
#if WINDOWS
"-windows10.0.19041.0";
#elif LINUX
"";
#elif MACCATALYST
"-maccatalyst";
#elif MACOS
"-macos";
#else
"";
#endif
#endif
static readonly bool isCI;
public static bool IsCI() => isCI;
}