Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Wix CustomAction C输入字符串格式错误_C#_Wix - Fatal编程技术网

C# Wix CustomAction C输入字符串格式错误

C# Wix CustomAction C输入字符串格式错误,c#,wix,C#,Wix,我正在尝试为.msi文件实现自定义操作。我要做的是为msi文件提供以下命令: msiexec /i somefile.msi /l*v output.txt IPADDRESS="127.0.0.1" PORT="9999" 基于上面的命令,我想创建一个包含以下内容的文件 { "ip":"127.0.0.1", "port" : "9999" } 现在,我已经实现了在上述场景中应该可以工作的以下代码: using System; using System.Collections.Gene

我正在尝试为.msi文件实现自定义操作。我要做的是为msi文件提供以下命令:

msiexec /i somefile.msi /l*v output.txt IPADDRESS="127.0.0.1" PORT="9999"
基于上面的命令,我想创建一个包含以下内容的文件

{
 "ip":"127.0.0.1",
 "port" : "9999"
}
现在,我已经实现了在上述场景中应该可以工作的以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;

namespace SetupCA
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult WriteFileToDisk(Session session)
        {
            session.Log("Begin WriteFileToDisk");

            string ipAddress = session["IPADDRESS"];
            string port = session["PORT"];
            string temp = @"
            {
            ""ip"" : ""{0}"" ,
            ""port"" : ""{1}""
            }";
            string config = string.Format(temp, ipAddress, port);
            session.Log("Config Generated was " + config);
            System.IO.File.WriteAllText(@"E:\lpa.config", config);            
            session.Log("Ending WriteFileToDisk");

            return ActionResult.Success;
        }
    }
}
运行我之前编写的命令时,output.txt中出现以下错误

Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Input string was not in a correct format.
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object args)
   at System.String.Format(IFormatProvider provider, String format, Object args)
   at System.String.Format(String format, Object arg0, Object arg1)
   at SetupCA.CustomActions.WriteFileToDisk(Session session)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
   at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)
我做错了什么?请帮助。

您必须在输入字符串中转义{和}。为此,您需要添加额外的{和}:


具体在哪一行?我编写的代码被编译成DLL,并在Wix自定义操作中调用。根据我给出的参数,错误被写入日志
string temp = @"
{{
    ""ip"" : ""{0}"" ,
    ""port"" : ""{1}""
}}";