Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the generated EXE work in all .NET framework versions?

Tags:

c#

dll

I'm very new to .NET world, I have a small console project (really small) that basically just reference an .DLL created in delphi (where most of the important code is), on my C# code I just have loops, thread sleep instructions and things like that.

My customers is using Microsoft Windows XP SP2, Microsoft XP SP3, Microsoft Windows Vista and Microsoft 7. I want to generate the .EXE in a way to run on all these environments. On my development environment with C# 2010 I have .NET framework 4.0, but I guess that some desktops at my customer has frameworks 3.5 and maybe older. Based on this situation, what is the best option to create the most portable EXE among new and old versions of .NET?

Detailed answer is very welcome since I'm beginner.

Since it may be my simple code, I'm pasting it here.

    using System;
    using System.Reflection;
    using System.Threading;
    using System.Web;
    using System.Diagnostics;
    using Redemption;

    namespace test{

class Program
{

    static void Main(string[] args)
    {


        RedemptionLoader.DllLocation64Bit = @"redemption64.dll";
        RedemptionLoader.DllLocation32Bit = @"redemption.dll";

        var ToEmailAddress = args[0];
        var subject = args[1];
        var pathFileAttach = args[2];

        SendMail(ToEmailAddress, subject, pathFileAttach);

    }

    private static void SendMail(string ToMail,string subject,string filePath) 
    {
        var session = new RDOSession();

        try
        {

            session.Logon();

            if (session.LoggedOn)
            {

                var Drafts = session.GetDefaultFolder(rdoDefaultFolders.olFolderDrafts);

                RDOMail msg = Drafts.Items.Add("IPM.Note");

                var body = "Test Redemption.";

                msg.To = ToMail;
                msg.Recipients.ResolveAll();
                msg.Subject = subject;
                msg.Body = body;

                msg.Attachments.Add(filePath);

                msg.Save();
                msg.Send();

                System.Threading.Thread.Sleep(5000);
            }
        }
        finally
        {
            session.Logoff();
            session = null;
        }
    }

}
}
like image 926
user1007489 Avatar asked Oct 21 '11 16:10

user1007489


3 Answers

Develop and build against .net 2.0 as the Target Framework and it will be compatible with all versions going forward.

like image 152
ChrisBint Avatar answered Oct 31 '22 14:10

ChrisBint


In the project menu you may select the version of .net you wish to use (use 2.0 as Chris said). Be careful, however, because sometimes by doing this, things may require some adjusting.

See here for a list of changes that may be important to you

It's also worth noting that under your project properties you may select what dependencies are required to run your application. It will check and allow the user to obtain these dependencies, such as a certain version of the framework, before allowing the install to progress.

like image 43
KreepN Avatar answered Oct 31 '22 15:10

KreepN


Be aware that v1.0 and 1.1 of the .NET Framework are extremely difficult to ensure compatibility with. Although all version of the .NET Framework are technically backwards-compatible, 1.0/1.1 are first very basic (they don't even have generic types), and second there were certain language and implementation details that changed significantly when v2.0 was released that actually may not be compatible with a post-2.0 framework. It was highly recommended by Microsoft that all .NET 1.1. programs be recompiled to target 2.0.

like image 40
KeithS Avatar answered Oct 31 '22 16:10

KeithS