如何使所有.NET framework版本生成的exe工作? [英] How to make the generated EXE work in all .NET framework versions?

查看:463
本文介绍了如何使所有.NET framework版本生成的exe工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是很新的.NET世界中,我有一个小控制台项目(非常小的),基本上只是参考德尔福(其中最重要的代码)创建了一个.DLL,我的C#代码,我只是有循环,线程休眠指令之类的东西。



我的客户是使用Microsoft Windows XP SP2中,微软XP SP3,微软Windows Vista和Microsoft 7.我想要生成的.EXE的方式对所有这些环境中运行。我与C#2010开发环境,我的.NET framework 4.0,但我想这一些桌面我的客户有3.5框架,也许更老。基于这种情况,什么是创建.NET之间的新老版本的最轻便的EXE的最佳选择?



详细的答案是非常值得欢迎的,因为我是初学者



由于这可能是我的简单的代码,我在这里将其粘贴。

 使用系统; 
使用的System.Reflection;
使用的System.Threading;
使用的System.Web;使用System.Diagnostics程序
;
使用赎回;

命名空间测试{

类节目
{

静态无效的主要(字串[] args)
{


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

变种ToEmailAddress = ARGS [0];
变种受试者= ARGS [1];
VAR pathFileAttach = ARGS [2];

的SendMail(ToEmailAddress,主题,pathFileAttach);

}

私有静态无效的SendMail(字符串ToMail,弦乐主题,字符串文件路径)
{
变种会话=新RDOSession();


{

session.Logon();

如果(session.LoggedOn)
{

VAR草稿= session.GetDefaultFolder(rdoDefaultFolders.olFolderDrafts);

RDOMail味精= Drafts.Items.Add(IPM.Note的);

VAR体=测试赎回。

msg.To = ToMail;
msg.Recipients.ResolveAll();
msg.Subject =主体;
msg.Body =身体;

msg.Attachments.Add(文件路径);

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

System.Threading.Thread.Sleep(5000);
}
}
终于
{
session.Logoff();
会话= NULL;
}
}

}
}


解决方案

开发和构建在.NET 2.0作为目标框架,这将是与所有版本的向前兼容。


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

}
}

解决方案

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

这篇关于如何使所有.NET framework版本生成的exe工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆