为什么我的C#没有System.ServiceProcess库?

时间:2013-11-04 07:45:35

标签: c# .net service assembly-references

这是代码。我只是想测试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);
        }
    }
}

然而,当我运行C#代码时,它说:

  

错误1类型或命名空间名称'ServiceProcess'不存在于   命名空间'System'(您是否缺少程序集引用?)

出了什么问题?

3 个答案:

答案 0 :(得分:45)

System.ServiceProcess命名空间属于System.ServiceProcess.dll,默认情况下不会添加为参考。

为此,在解决方案窗口中,右键单击“引用”并选择“添加引用”。转到.NET选项卡,然后双击 System.ServiceProcess.dll 。 / p>

enter image description here

此程序集可能位于C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727文件夹中。

答案 1 :(得分:4)

您还需要添加对相应.dll的引用。

右键点击该项目 - >添加参考 - >装配 - >框架 - > System.ServiceProcess

答案 2 :(得分:2)

你应该从框架列表中添加它 右键单击项目 - >添加参考 - >在“Assemblies”下搜索 - >选择 - >确定

enter image description here

相关问题