简体   繁体   English

如何从C#应用程序调用cmd生成nsis安装程序?

[英]How to call cmd from C# application to generate nsis installer?

I am trying to call a command prompt from a C# application and then the command prompt will run an argument to generate a nsis installer. 我试图从C#应用程序调用命令提示符,然后命令提示符将运行一个参数以生成nsis安装程序。

So this is the function inside the C# application which generate the installer: 因此,这是生成安装程序的C#应用​​程序内部的函数:

    private bool GenerateInstaller(string pStrVersion)
    {
        bool IsSuccess = false;

        Process process = new Process();
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
        startInfo.FileName = "cmd.exe";

        System.Diagnostics.Debug.WriteLine("Installer version: " + pStrVersion);

        if(pStrVersion == "PRO")
        {
            startInfo.Arguments = @"""C:\Program Files (x86)\NSIS\makensis.exe"" ""Z:\Project\BuildArea\workspace\installer\Setup_PRO.nsi""";
            System.Diagnostics.Debug.WriteLine("argument: " + startInfo.Arguments);
            process.StartInfo = startInfo;
            process.Start();
            IsSuccess = true;
        } 
        else 
        {
            startInfo.Arguments = @"""C:\Program Files (x86)\NSIS\makensis.exe"" ""Z:\Project\BuildArea\workspace\installer\Setup_STD.nsi""";
            System.Diagnostics.Debug.WriteLine("argument: " + startInfo.Arguments);
            process.StartInfo = startInfo;
            process.Start();
            IsSuccess = true;
        }

        return IsSuccess;
    }

The problem is when I try to run the C# app, it doesn't generate the installer. 问题是当我尝试运行C#应用程序时,它不会生成安装程序。 At the first time, I thought the string argument is wrong. 第一次,我认为string参数是错误的。 So, I opened a new command prompt and try to run the argument directly and it works. 因此,我打开了一个新的命令提示符,并尝试直接运行该参数,它可以工作。

Do you have any idea what's wrong with my code? 您知道我的代码有什么问题吗?

Why don't you start makensis.exe directly? 为什么不直接启动makensis.exe?

startInfo.FileName = @"C:\Program Files (x86)\NSIS\makensis.exe";
startInfo.Arguments = @"Z:\Project\BuildArea\workspace\installer\Setup_PRO.nsi";
process.StartInfo = startInfo;
process.Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM