The problem I am having is that I need to reference a dll this is rebuilt every hour and are placed into a unique directory. So every couple hours I have to go to the newest directory and reference that dll for mt project.

What I did so far is created a script that can find the most recent dll in the right directory using the pre-build event. The only problem is I cannot figure out how to reference the dlls in the pre-build event.

Does anyone got any ideas?

I am using visual studio and i am making a windows form app.

You can use reflection to load an assembly at runtime.

Consider this code compiled into Foo.dll

namespace Foo
{
    public class Bar
    {
        public string Blah()
        {
            return "Blah";
        }
    }
}

And then in another program

using System;
using System.Reflection;

class Program
{
    static void Main(string[] args)
    {
        Assembly assembly = Assembly.LoadFile(@"C:\Users\Anthony\Documents\Visual Studio 2008\Projects\Foo\Foo\bin\Release\Foo.dll");

        object o = assembly.CreateInstance("Foo.Bar");

        Type type = o.GetType();
        MethodInfo methodInfo = type.GetMethod("Blah");

        string output = (string)methodInfo.Invoke(o, null);
        Console.WriteLine(output);

        Console.Read();
    }
}

How to pass the parametes to dll with this example? can anyone answer please?

You can pass through Constructor, Or Take a look at invoking delegate function.

sorry

You can do one more thing Go to Visual Studio Properties --> Build Events --> In a Post Build Event --> Type like this copy "Your Source Location" "Destination Location",. Thats it. Visual studio will take care the rest of the things. i.e., it will copy the DLL From Source Location to Destination Location on every new Build

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.