4

我想用 c# 代码通过 nant 脚本杀死所有 IE 实例:

<target name="clean">  
   <script language="C#" prefix="Cleaning">          
          <references>
              <include name="System.Diagnostics.dll" />
          </references>
                <imports>
                    <import namespace="System.Diagnostics" />
                </imports>
          <code>
            <![CDATA[

              [Function("Delete")]
              public static void KillIe() 
              {                     

                foreach (var process in Process.GetProcessesByName("iexplore"))
                {
                  process.Kill();
                }         

              }
            ]]>
          </code>
      </script>
 <echo message="Calling function: ${Cleaning::KillIe()}"/> 
  </target>    
</project>

当我执行此脚本时,我收到以下错误:

错误 CS0234:命名空间“System.Diagnostics”中不存在类型或命名空间名称“Process”(您是否缺少程序集引用?)

这里有什么问题?

4

1 回答 1

4

我遇到了类似的问题,最后我在 NAnt 代码中添加了以下引用:

<script ... >
  <references>
    <include name="System.dll"/>
    ...
  </references>
  <code>
    ...
  </code>
</script>

您应该System.dll明确添加 - 它不在默认包含的程序集列表中

于 2012-08-20T09:23:55.010 回答