怎么引用.NET可执行文件*.exe中的类

    如果我们要引用一个.NET可执行文件*.exe中的类,使用命令行编译是非常简单的。我们只需要在csc的参数中加上/reference:"*.exe"就行了,可是如果要在VS.NET中引用同样的exe文件并编译,居然默认是不行的

    比如我们在VS.NET 2003里面引用一个叫HelloWorld.exe的托管可执行文件,会得到如下的错误:

---------------------------
Microsoft Development Environment
---------------------------
    A reference to 
'E:\HelloWorld.exe' could not be added. This is not a valid assembly or COM component.  Only assemblies with extension 'dll' and COM components can be referenced.  Please make sure that the file is accessible, and that it is a valid assembly or COM component.
---------------------------
OK   
---------------------------

    对于.NET的assembly,exe和dll的区别就exe文件有一个被标志为entrypoint的静态方法。鉴于此我们把exe文件rename为dll,再次在VS.NET 2003中去引用,就ok了

    这里应该说是VS.NET 2003的一个bug,因为在它的Add Reference的文件选择列表框中,是支持:*.dll, *.tlb, *olb, *.ocx, *.exe这些文件类型的。

    同时,在VS.NET 2005 beta2中就可以直接添加对托管的*.exe文件的引用。

posted on 2005-04-24 14:58  birdshome  阅读(4693)  评论(3编辑  收藏  举报

导航