Skip to content

Commit 672f46a

Browse files
committed
Improve performance of ParseDotNetVersions task
This was suggested by Michael Simons in code review. - Simplify the LINQ expression. - Invoke `dotnet --list-runtimes` only once and keep the results.
1 parent 139eaaf commit 672f46a

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/ParseDotNetVersions.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,28 @@ public class ParseDotNetVersions : Task
3030

3131
public override bool Execute()
3232
{
33-
3433
var pathToDotNet = Path.Join(SdkRootDirectory, "dotnet");
34+
3535
SdkVersion = ExecuteDotNetCommand(SdkRootDirectory,
3636
pathToDotNet,
3737
new List<string> { "--list-sdks" })
3838
.First()
3939
.Split(" ")
4040
.First();
41-
AspNetCoreVersion = ExecuteDotNetCommand(SdkRootDirectory,
42-
pathToDotNet,
43-
new List<string> { "--list-runtimes" })
44-
.Where(line => line.Contains("Microsoft.AspNetCore.App"))
45-
.First()
46-
.Split(" ")
47-
.Skip(1)
48-
.First();
49-
RuntimeVersion = ExecuteDotNetCommand(SdkRootDirectory,
50-
pathToDotNet,
51-
new List<string> { "--list-runtimes"})
52-
.Where(line => line.Contains("Microsoft.NETCore.App"))
53-
.First()
54-
.Split(" ")
55-
.Skip(1)
56-
.First();
41+
42+
var runtimesOutput = ExecuteDotNetCommand(SdkRootDirectory,
43+
pathToDotNet,
44+
new List<string> { "--list-runtimes" });
45+
46+
AspNetCoreVersion = runtimesOutput
47+
.First(line => line.Contains("Microsoft.AspNetCore.App"))
48+
.Split(" ")
49+
.ElementAt(1);
50+
51+
RuntimeVersion = runtimesOutput
52+
.First(line => line.Contains("Microsoft.NETCore.App"))
53+
.Split(" ")
54+
.ElementAt(1);
5755

5856
return true;
5957
}

0 commit comments

Comments
 (0)