4
votes

I want to kill all IE instances by nant script with c# code:

<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>

When I execute this script I get the following error:

error CS0234: The type or namespace name 'Process' does not exist in the namespace 'System.Diagnostics' (are you missing an assembly reference?)

What is wrong here?

1

1 Answers

4
votes

I had a similar issue and I ended up adding the following reference to the NAnt code:

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

You should add System.dll explicitly - it is not in the list of assemblies included by default.