为什么我的 C# 没有 System.ServiceProcess 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19763527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why my C# does not have System.ServiceProcess Library?
提问by user1535147
This is the code. I just wanna test the library of System.ServiceProcess library.
这是代码。我只是想测试 System.ServiceProcess 库的库。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceProcess;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hi");
var srv = new ServiceController("MyService");
Console.WriteLine("MyService Status {0}", srv.Status);
if (srv.Status != ServiceControllerStatus.Running)
srv.Start();
System.Threading.Thread.Sleep(1000000);
}
}
}
However, when I run the C# code, its says:
但是,当我运行 C# 代码时,它说:
Error 1 The type or namespace name 'ServiceProcess' does not exist in the namespace 'System' (are you missing an assembly reference?)
错误 1 命名空间“System”中不存在类型或命名空间名称“ServiceProcess”(您是否缺少程序集引用?)
What went wrong?
什么地方出了错?
采纳答案by Soner G?nül
System.ServiceProcess
namespace belongs on System.ServiceProcess.dll
and it doesn't added as a reference by default.
System.ServiceProcess
命名空间所属System.ServiceProcess.dll
,默认情况下不添加为引用。
For this, in the solution window, right click on "References" and choose "Add Reference.." Go to the .NET tab, and double click on System.ServiceProcess.dll.
为此,在解决方案窗口中,右键单击“引用”并选择“添加引用..”转到 .NET 选项卡,然后双击System.ServiceProcess.dll。
This assembly is probably in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
folder.
这个程序集可能在C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
文件夹中。
回答by walther
You need to add a reference to the corresponding .dll as well.
您还需要添加对相应 .dll 的引用。
Right click on the project -> Add Reference -> Assemblies -> Framework -> System.ServiceProcess
右键单击项目 -> 添加引用 -> 程序集 -> 框架 -> System.ServiceProcess