Skip to content

Commit 4fe3ff7

Browse files
committed
Getting target framework from Directory.Build.props
1 parent 53c0ad6 commit 4fe3ff7

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/taskman/tasks.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Xml.Linq;
45
using ThreadTask = System.Threading.Tasks.Task;
56

67
#pragma warning disable CS8981
@@ -20,6 +21,21 @@ public static string BHL_ROOT
2021
}
2122
}
2223

24+
private static string _targetFramework;
25+
26+
public static string TargetFramework
27+
{
28+
get
29+
{
30+
if(_targetFramework == null)
31+
{
32+
var doc = XDocument.Parse(File.ReadAllText(BHL_ROOT + "/Directory.Build.props"));
33+
_targetFramework = doc.Root.Element("PropertyGroup").Element("TargetFramework").Value;
34+
}
35+
return _targetFramework;
36+
}
37+
}
38+
2339
const int ERROR_EXIT_CODE = 2;
2440

2541
[Task(verbose: false)]
@@ -62,8 +78,7 @@ public static string DotnetBuildLibrary(
6278
bool force,
6379
string[] srcs,
6480
string result,
65-
List<string> defines,
66-
string framework = "net8.0"
81+
List<string> defines
6782
)
6883
{
6984
var files = new List<string>();
@@ -100,8 +115,7 @@ public static string DotnetBuildLibrary(
100115
files,
101116
deps,
102117
pkgs,
103-
defines,
104-
framework
118+
defines
105119
);
106120

107121
string result_dll = result + "/" + Path.GetFileName(result);
@@ -125,13 +139,13 @@ public static string DotnetBuildLibrary(
125139
{
126140
try
127141
{
128-
tm.Shell("dotnet", "clean --framework " + framework + " " + csproj_file);
142+
tm.Shell("dotnet", "clean --framework " + TargetFramework + " " + csproj_file);
129143
}
130144
catch(Exception)
131145
{}
132146
}
133147

134-
tm.Shell("dotnet", "build --framework " + framework + " " + csproj_file + " -o " + result);
148+
tm.Shell("dotnet", "build --framework " + TargetFramework + " " + csproj_file + " -o " + result);
135149

136150
//let's force file modification time since .Net may use result from the cache
137151
//without changing the file time
@@ -146,8 +160,7 @@ public static string MakeLibraryCSProj(
146160
List<string> files,
147161
List<string> deps,
148162
List<string> pkgs,
149-
List<string> defines,
150-
string framework
163+
List<string> defines
151164
)
152165
{
153166
string csproj_header = @$"
@@ -156,7 +169,7 @@ string framework
156169
<AssemblyName>{name}</AssemblyName>
157170
<OutputType>Library</OutputType>
158171
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
159-
<TargetFramework>{framework}</TargetFramework>
172+
<TargetFramework>{TargetFramework}</TargetFramework>
160173
<DefineConstants>{string.Join(';', defines)}</DefineConstants>
161174
</PropertyGroup>
162175
";

0 commit comments

Comments
 (0)