How to make the generated EXE work in all .NET fra

2019-05-03 17:20发布

问题:

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;
        }
    }

}
}

回答1:

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



回答2:

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.



回答3:

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.



回答4:

While targeting version 2.0 of the framework is probably a good idea in this case as you've got a fairly simple app, you should also create an installer that will detect which version of .NET the client has installed and install the correct one if required.

There are various ways to do this, but ClickOnce comes as part of Visual Studio and is very easy to set up. It doesn't create a large installation exe as it downloads the required version of .NET from Microsoft when it's run.



回答5:

The lower the Framework that you build against, the more portable your application will be. What Framework you can build against depends on what you are using in your code. As noted by someone else, keep in mind that some of those Operating Systems will still require the relevant .NET Framework be installed as it is not included.



回答6:

.NET 2.0 is usually consider the framework to use when you want to be universal. Most code samples are written in 2.0. However you need to realize you shouldn't assume .Net is going to be installed by default. Some older machines will have to install it. Very few won't have at least 2.0 by now, but it is not assumption I would make unless your willing to risk having people not be able install your software and not know why. Windows XP does not come with .NET by default.



标签: c# dll