Missing reference to System.Diagnostics.Process

后端 未结 2 755
北荒
北荒 2020-12-12 00:45

I have a app that I am building to shut down a computer

I tried using using System.Management; but it tells me to add a reference, No such thing in the add re

相关标签:
2条回答
  • 2020-12-12 00:59

    There's one simple explanation for a mystifying problem like this: you are using the Portable Class Libraries or have selected the ".NET for Metro style apps" platform target. Which does not permit using the Process class, Metro apps operate in a sandbox that disables many standard .NET features. Starting another process or shutting down the OS is not permitted, only the user can do that.

    You'll have to give up on Metro if this is important to you, your app needs to run as a desktop app. And won't run on a slate that boots Win8.

    0 讨论(0)
  • 2020-12-12 01:00

    I ended up

    1. upgrading to the latest Visual Studio 2015 SP3,
    2. running Scott Smith's upgrade command using powershell,

      powershell dnvm upgrade -r coreclr
      

      https://stackoverflow.com/a/34013990/80772

    3. creating a console project anew from Visual Studio.

    After adding more packages required to resolve the standard classes I observed this global.json,

    {
      "projects": [ "src", "test" ],
      "sdk": {
        "version": "1.0.0-preview2-003131"
      }
    }
    

    and this project.json,

    {
      "version": "1.0.0-*",
      "buildOptions": {
        "emitEntryPoint": true
      },
    
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.1"
        },
        "system.diagnostics.textwritertracelistener": "4.0.0-beta-23123",
        "System.Diagnostics.TraceSource": "4.0.0",
        "System.IO": "4.1.0"
      },
    
      "frameworks": {
        "netcoreapp1.0": {
          "imports": "dnxcore50"
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题