forked from dotnet/docfx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use AdHocWorkspace instead of MSBuildWorkspace (dotnet#1963).
Remove support for project.json (we only support MSBuild-style projects now).
- Loading branch information
Showing
9 changed files
with
591 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/Microsoft.DocAsCode.Metadata.ManagedReference/MSBuildWorkspaces/DotNetRuntimeInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.DocAsCode.Metadata.ManagedReference.MSBuildWorkspaces | ||
{ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Diagnostics; | ||
|
||
/// <summary> | ||
/// Information about the .NET Core runtime. | ||
/// </summary> | ||
public class DotNetRuntimeInfo | ||
{ | ||
/// <summary> | ||
/// A cache of .NET runtime information by target directory. | ||
/// </summary> | ||
static readonly ConcurrentDictionary<string, DotNetRuntimeInfo> _cache = new ConcurrentDictionary<string, DotNetRuntimeInfo>(); | ||
|
||
/// <summary> | ||
/// The .NET Core version. | ||
/// </summary> | ||
public string Version { get; set; } | ||
|
||
/// <summary> | ||
/// The .NET Core base directory. | ||
/// </summary> | ||
public string BaseDirectory { get; set; } | ||
|
||
/// <summary> | ||
/// The current runtime identifier (RID). | ||
/// </summary> | ||
public string RID { get; set; } | ||
|
||
/// <summary> | ||
/// Get information about the current .NET Core runtime. | ||
/// </summary> | ||
/// <param name="baseDirectory"> | ||
/// An optional base directory where dotnet.exe should be run (this may affect the version it reports due to global.json). | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="DotNetRuntimeInfo"/> containing the runtime information. | ||
/// </returns> | ||
public static DotNetRuntimeInfo GetCurrent(string baseDirectory = null) | ||
{ | ||
return _cache.GetOrAdd(baseDirectory, _ => | ||
{ | ||
DotNetRuntimeInfo runtimeInfo = new DotNetRuntimeInfo(); | ||
|
||
Process dotnetInfoProcess = Process.Start(new ProcessStartInfo | ||
{ | ||
FileName = "dotnet", | ||
WorkingDirectory = baseDirectory, | ||
Arguments = "--info", | ||
UseShellExecute = false, | ||
RedirectStandardOutput = true | ||
}); | ||
using (dotnetInfoProcess) | ||
{ | ||
dotnetInfoProcess.WaitForExit(); | ||
|
||
string currentSection = null; | ||
string currentLine; | ||
while ((currentLine = dotnetInfoProcess.StandardOutput.ReadLine()) != null) | ||
{ | ||
if (String.IsNullOrWhiteSpace(currentLine)) | ||
continue; | ||
|
||
if (!currentLine.StartsWith(" ")) | ||
{ | ||
currentSection = currentLine; | ||
|
||
continue; | ||
} | ||
|
||
string[] property = currentLine.Split(new char[] { ':' }, count: 2); | ||
if (property.Length != 2) | ||
continue; | ||
|
||
property[0] = property[0].Trim(); | ||
property[1] = property[1].Trim(); | ||
|
||
switch (currentSection) | ||
{ | ||
case "Product Information:": | ||
{ | ||
switch (property[0]) | ||
{ | ||
case "Version": | ||
{ | ||
runtimeInfo.Version = property[1]; | ||
|
||
break; | ||
} | ||
} | ||
|
||
break; | ||
} | ||
case "Runtime Environment:": | ||
{ | ||
switch (property[0]) | ||
{ | ||
case "Base Path": | ||
{ | ||
runtimeInfo.BaseDirectory = property[1]; | ||
|
||
break; | ||
} | ||
case "RID": | ||
{ | ||
runtimeInfo.RID = property[1]; | ||
|
||
break; | ||
} | ||
} | ||
|
||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return runtimeInfo; | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Clear the cache of .NET runtime information. | ||
/// </summary> | ||
public static void ClearCache() | ||
{ | ||
_cache.Clear(); | ||
} | ||
} | ||
} |
Oops, something went wrong.