Nant does not see reference

喜夏-厌秋 提交于 2019-12-12 15:25:15

问题


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:


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.



来源:https://stackoverflow.com/questions/12034592/nant-does-not-see-reference

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!