C# 如何将exe绑定/合并到我的程序中?

C# 如何将exe绑定/合并到我的程序中?,c#,C#,我正在使用System.Diagnostics.Process.Start(“my.exe”)以调用exe 现在我可以调用我的.exe了,我想将它绑定/合并到我的c#应用程序中,这样当我构建我的应用程序时,我就可以在projectName\Debug\builtProgram.exe中构建exe,或者以任何其他方式最终获得一个包含我所需exe文件的exe文件 例如,考虑我创建一个程序A,我希望它把它封装在另一个程序B中,它只包含一个按钮“启动程序A”。假设程序B是可移植的,只有一个exe文件。

我正在使用
System.Diagnostics.Process.Start(“my.exe”)以调用exe

现在我可以调用我的.exe了,我想将它绑定/合并到我的c#应用程序中,这样当我构建我的应用程序时,我就可以在projectName\Debug\builtProgram.exe中构建exe,或者以任何其他方式最终获得一个包含我所需exe文件的exe文件

例如,考虑我创建一个程序A,我希望它把它封装在另一个程序B中,它只包含一个按钮“启动程序A”。假设程序B是可移植的,只有一个exe文件。
问题是-如何创建程序B?

您可以在.NET程序集中包含.exe作为,然后在启动时将其转储到磁盘中的临时文件中:

var thisAssembly = Assembly.GetExecutingAssembly();
var executableFileName = Path.GetTempFileName();
using(resourceStream = thisAssembly.GetManifestResourceStream("name.of.resource.exe"))
using(fileStream = File.Create(executableFileName))
{
     resourceStream.CopyTo(fileStream);
}
然后你会像平常一样叫它

Process.Start(executableFileName);

您可以将.exe作为一个文件包含在.NET程序集中,然后在启动时将其转储到磁盘上的临时文件中:

var thisAssembly = Assembly.GetExecutingAssembly();
var executableFileName = Path.GetTempFileName();
using(resourceStream = thisAssembly.GetManifestResourceStream("name.of.resource.exe"))
using(fileStream = File.Create(executableFileName))
{
     resourceStream.CopyTo(fileStream);
}
然后你会像平常一样叫它

Process.Start(executableFileName);

因为我很难提取嵌入式资源。
以下是我的答案:

        public static void getbytez(string file, string outp)
    {
        byte[] buffer = File.ReadAllBytes(file);
        string base64Encoded = Convert.ToBase64String(buffer);
        File.WriteAllText(outp+ ".txt", base64Encoded);
        //copy the base64encoded text.
        //Code by CursedGmod. credit me please :D
    }
    public static void extract2idk(string txtfile, string outp, string exten)
    {
        byte[] gu = Convert.FromBase64String(txtfile);
        // use it like this: byte[] gu = Convert.FromBase64String(your base64 converted text that you copied from the txt file);
        // or use File.ReadAllText if you're making a stub builder.
        File.WriteAllBytes(outp + exten, gu);
        Process.Start(Environment.ExpandEnvironmentVariables("%TEMP%") + Path.GetFileName(txtfile));
    }

因为我很难提取嵌入式资源。
以下是我的答案:

        public static void getbytez(string file, string outp)
    {
        byte[] buffer = File.ReadAllBytes(file);
        string base64Encoded = Convert.ToBase64String(buffer);
        File.WriteAllText(outp+ ".txt", base64Encoded);
        //copy the base64encoded text.
        //Code by CursedGmod. credit me please :D
    }
    public static void extract2idk(string txtfile, string outp, string exten)
    {
        byte[] gu = Convert.FromBase64String(txtfile);
        // use it like this: byte[] gu = Convert.FromBase64String(your base64 converted text that you copied from the txt file);
        // or use File.ReadAllText if you're making a stub builder.
        File.WriteAllBytes(outp + exten, gu);
        Process.Start(Environment.ExpandEnvironmentVariables("%TEMP%") + Path.GetFileName(txtfile));
    }

它是一个.NETEXE吗?那就简单了。不,这完全是另一个程序。用C++编写的你是在说ilmerge吗@肯尼:既然它不是.NET exe,ILMerge就不能工作了。@Martinho,我不清楚,但这是真的。它是.NET exe吗?那就简单了。不,这完全是另一个程序。用C++编写的你是在说ilmerge吗@肯尼:因为它不是.NET exe,ILMerge将无法工作。@Martinho,我不清楚,但这是真的。@Ravi:更新了答案以包含示例。如果.NET 4.0之前的CopyTo不可用,请参阅@Ravi:更新了答案以包含示例。如果.NET 4.0之前的CopyTo不可用,请参阅