зеркало из https://github.com/microsoft/BuildXL.git
[.NET Core] Add a reference to System.Management and use it for querying child processes (#314)
- add System.Management nuget - remove define constants: - DISABLE_FEATURE_MEMORYMAP_SECURITY - DISABLE_FEATURE_SYSTEM_MANAGEMENT AB#1521781
This commit is contained in:
Родитель
a1abe06963
Коммит
99fccac9a2
|
@ -6,7 +6,7 @@ import * as Deployment from "Sdk.Deployment";
|
|||
@@public
|
||||
export interface Framework {
|
||||
/**
|
||||
* The minimum rumtime version supported.
|
||||
* The minimum runtime version supported.
|
||||
* See: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/startup/supportedruntime-element
|
||||
*/
|
||||
supportedRuntimeVersion: string,
|
||||
|
|
|
@ -379,8 +379,6 @@ function processArguments(args: Arguments, targetType: Csc.TargetType) : Argumen
|
|||
...addIf(isDotNetCoreBuild,
|
||||
"FEATURE_CORECLR",
|
||||
"FEATURE_SAFE_PROCESS_HANDLE",
|
||||
"DISABLE_FEATURE_MEMORYMAP_SECURITY",
|
||||
"DISABLE_FEATURE_SYSTEM_MANAGEMENT",
|
||||
"DISABLE_FEATURE_HTTPEXCEPTION",
|
||||
"DISABLE_FEATURE_VSEXTENSION_INSTALL_CHECK",
|
||||
"DISABLE_FEATURE_SECURITY_ATTRIBUTES",
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
import * as Managed from "Sdk.Managed";
|
||||
import * as Shared from "Sdk.Managed.Shared";
|
||||
import * as SysMng from "System.Management";
|
||||
|
||||
namespace Processes {
|
||||
export declare const qualifier : BuildXLSdk.DefaultQualifierWithNet461;
|
||||
|
||||
|
@ -16,6 +19,13 @@ namespace Processes {
|
|||
BuildXLSdk.NetFx.System.IO.Compression.dll,
|
||||
BuildXLSdk.NetFx.System.Management.dll
|
||||
),
|
||||
...addIf(BuildXLSdk.isDotNetCoreBuild,
|
||||
SysMng.pkg.override<Shared.ManagedNugetPackage>({
|
||||
runtime: Context.getCurrentHost().os === "win" ? [
|
||||
Shared.Factory.createBinaryFromFiles(SysMng.Contents.all.getFile(r`runtimes/win/lib/netcoreapp2.0/System.Management.dll`))
|
||||
] : []
|
||||
})
|
||||
),
|
||||
...importFrom("BuildXL.Utilities").Native.securityDlls,
|
||||
importFrom("BuildXL.Pips").dll,
|
||||
importFrom("BuildXL.Utilities").dll,
|
||||
|
|
|
@ -10,13 +10,11 @@ using System.Globalization;
|
|||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Runtime.InteropServices;
|
||||
using BuildXL.Native.IO;
|
||||
using BuildXL.Native.Processes.Windows;
|
||||
using BuildXL.Utilities;
|
||||
#if !DISABLE_FEATURE_SYSTEM_MANAGEMENT
|
||||
using System.Management;
|
||||
#endif
|
||||
|
||||
namespace BuildXL.Processes
|
||||
{
|
||||
|
@ -266,28 +264,24 @@ namespace BuildXL.Processes
|
|||
|
||||
Process p = maybeProcess.Result;
|
||||
result.Add(new KeyValuePair<string, int>("1_" + p.ProcessName + ".exe", p.Id));
|
||||
#if !DISABLE_FEATURE_SYSTEM_MANAGEMENT
|
||||
foreach (var child in GetChildProcessTreeIds(parentProcessId, maxTreeDepth - 1))
|
||||
{
|
||||
result.Add(new KeyValuePair<string, int>("1_" + child.Key, child.Value));
|
||||
}
|
||||
#endif // If we don't have access to get the process tree, we'll still at least get the root process. But we need to
|
||||
|
||||
// figure out a way to get the process tree under CoreCLR
|
||||
return result;
|
||||
}
|
||||
|
||||
#if !DISABLE_FEATURE_SYSTEM_MANAGEMENT
|
||||
internal static List<KeyValuePair<string, int>> GetChildProcessTreeIds(int parentProcessId, int maxTreeDepth)
|
||||
{
|
||||
List<KeyValuePair<string, int>> result = new List<KeyValuePair<string, int>>();
|
||||
|
||||
// If we don't have access to get the process tree, we'll still at least get the root process.
|
||||
try
|
||||
{
|
||||
if (maxTreeDepth > 0)
|
||||
{
|
||||
var query = new ObjectQuery("select * from win32_process where ParentProcessId=" + parentProcessId);
|
||||
using (var searcher = new ManagementObjectSearcher(query))
|
||||
using (var searcher = new ManagementObjectSearcher("select * from win32_process where ParentProcessId=" + parentProcessId))
|
||||
{
|
||||
var childProcesses = searcher.Get();
|
||||
|
||||
|
@ -317,7 +311,6 @@ namespace BuildXL.Processes
|
|||
throw new BuildXLException("Failed to enumerate child processes", ex);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private static Possible<Process> TryGetProcesById(int processId)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Processes {
|
|||
importFrom("BuildXL.Utilities").Storage.dll,
|
||||
importFrom("BuildXL.Utilities.Instrumentation").Common.dll,
|
||||
importFrom("BuildXL.Utilities.UnitTests").TestProcess.exe,
|
||||
...importFrom("BuildXL.Utilities").Native.securityDlls,
|
||||
...importFrom("BuildXL.Utilities").Native.securityDlls
|
||||
],
|
||||
runtimeContent: [
|
||||
...addIfLazy(qualifier.targetRuntime === "win-x64", () => [
|
||||
|
|
|
@ -380,9 +380,6 @@ namespace Test.BuildXL.Storage
|
|||
mapName: null,
|
||||
capacity: 0,
|
||||
access: MemoryMappedFileAccess.ReadWrite,
|
||||
#if !DISABLE_FEATURE_MEMORYMAP_SECURITY
|
||||
memoryMappedFileSecurity: null,
|
||||
#endif
|
||||
inheritability: HandleInheritability.None,
|
||||
leaveOpen: false))
|
||||
{
|
||||
|
|
|
@ -1104,9 +1104,6 @@ namespace Test.BuildXL.Storage
|
|||
mapName: null,
|
||||
capacity: 0,
|
||||
access: MemoryMappedFileAccess.ReadWrite,
|
||||
#if !DISABLE_FEATURE_MEMORYMAP_SECURITY
|
||||
memoryMappedFileSecurity: null,
|
||||
#endif
|
||||
inheritability: HandleInheritability.None,
|
||||
leaveOpen: false))
|
||||
{
|
||||
|
|
|
@ -318,6 +318,7 @@ config({
|
|||
{ id: "System.Linq.Expressions", version: "4.3.0" },
|
||||
{ id: "System.Linq.Parallel", version: "4.3.0" },
|
||||
{ id: "System.Linq.Queryable", version: "4.3.0" },
|
||||
{ id: "System.Management", version: "4.6.0-preview5.19224.8" },
|
||||
{ id: "System.Net.Http", version: "4.3.0" },
|
||||
{ id: "System.Net.NameResolution", version: "4.3.0" },
|
||||
{ id: "System.Net.NetworkInformation", version: "4.3.0" },
|
||||
|
|
Загрузка…
Ссылка в новой задаче