How to add exe as reference in my web application
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)
开发者_如何学JAVA {
//Do something
return "<the result>";
}
}
}
I want to add reference this exe into my web application to call (SampleString) methods in side the exe. Is it possible in .net and how can I achieve this?
Yes - just add it as if it were a class library. Visual Studio has supported this since 2005.
EDIT: Okay, it sounds like ASP.NET may not like .exe assemblies :(
In that case I suggest you extract the code from your current executable and put it into a class library. You may find it easier to change the whole 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.
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).
I think the missing assembly message is probably a red herring, if you've added a reference successfully and get this message when you try to use it, I've always found this is due to targeting different versions of framework (usually the Client Profile version being defaulted).
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.
Yes.
Just go to the Project
menu, select Add Reference
change to the Browse
tab and find and select the executable.
精彩评论