代码之家  ›  专栏  ›  技术社区  ›  SelvaS

How to add exe as reference in my web application

  •  2
  • SelvaS  · 技术社区  · 14 年前

    I have created an exe with some methods in it (ref example exe below).

    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    
    namespace SampleRef  
    {  
      public class Program  
      {  
      static void Main(string[] args)  
        {  
        }  
      }  
      public class Sample  
      {    
       public Sample(int count)  
        {
    
        }
    
        public string SampleString(int InputValue)
        {
          //Do something
           return "<the result>";
        }
      }  
    }  
    

    我想将引用这个exe添加到我的Web应用程序中,以调用exe一侧的(sampleString)方法。在.NET中是可能的吗?我如何才能做到这一点?

    4 回复  |  直到 12 年前
        1
  •  2
  •   Jon Skeet    14 年前

    Yes - just add it as if it were a class library. Visual Studio has supported this since 2005.

    编辑:好吧,听起来好像ASP.NET可能不喜欢.exe程序集:

    在这种情况下,我建议您从当前的可执行文件中提取代码并将其放入类库中。你可能会发现更容易改变 整体 of your normal application into a DLL - and just add another executable project which does nothing but call into the DLL to start the "application". That shouldn't be the end-point of your code, but it's an easy way to get up and running.

        2
  •  2
  •   deadcrab    12 年前

    You definitely can add and use a reference to an exe in exactly the same way that you would a dll (.net 4 at least).

    我认为丢失的程序集消息可能是一个红鲱鱼,如果您成功地添加了一个引用,并在尝试使用它时获得了这个消息,我总是发现这是由于针对不同版本的框架(通常是默认的客户机配置文件版本)。

        3
  •  1
  •   this. __curious_geek    14 年前

    Final compiled output in .Net is called Assemblies and EXEs are no different in this case. It's just that they carry a special header that identify them as executables with program entry points and normal compiled dll assemblies don't have this, but both are assemblies and you can add assemblies as reference in any .net project you're working on.

        4
  •  0
  •   Hans Olsson    14 年前

    对。

    只要去 Project 菜单选择 Add Reference 改为 Browse tab and find and select the executable.