【发布时间】:2016-06-25 13:24:02
【问题描述】:
当我尝试在 Unity3d 中运行我的游戏时,它在编译器的 CocoaPodHelper.cs 文件中出现了这个错误
Process ` :type 在 using 语句中使用必须可以隐式转换为 system.idisposable
“using (var process = new Process())”之后的任何内容都充满了错误。
这里是 cocapodhelper.cs 的代码
using System;
using System.Diagnostics;
using System.IO;
namespace GoogleMobileAds
{
public class CocoaPodHelper
{
public static string Update(string projDir)
{
if (!Directory.Exists(projDir))
{
throw new Exception("project not found: " + projDir);
}
string podPath = ExecuteCommand("which", "pod", null);
if (podPath.Equals(""))
{
throw new Exception("pod executable not found");
}
return ExecuteCommand(podPath.Trim(), "update", projDir);
}
private static string ExecuteCommand(string command, string argument, string workingDir)
{
using (var process = new Process())
{
if (!process.StartInfo.EnvironmentVariables.ContainsKey("LANG"))
{
process.StartInfo.EnvironmentVariables.Add("LANG", "en_US.UTF-8");
}
string path = process.StartInfo.EnvironmentVariables["PATH"];
if(!path.Contains("/usr/local/bin"))
{
path = path + ":/usr/local/bin";
process.StartInfo.EnvironmentVariables.Remove("PATH");
process.StartInfo.EnvironmentVariables.Add("PATH", path);
}
if (workingDir != null)
{
process.StartInfo.WorkingDirectory = workingDir;
}
process.StartInfo.FileName = command;
process.StartInfo.Arguments = argument;
UnityEngine.Debug.Log("Executing " + command + " argument: " +
process.StartInfo.Arguments);
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
try
{
process.Start();
process.StandardError.ReadToEnd();
var stdOutput = process.StandardOutput.ReadToEnd();
var stdError = process.StandardError.ReadToEnd();
UnityEngine.Debug.Log("command stdout: " + stdOutput);
if (stdError != null && stdError.Length > 0)
{
UnityEngine.Debug.LogError("command stderr: " + stdError);
}
if (!process.WaitForExit(10 * 1000))
{
throw new Exception("command did not exit in a timely fashion");
}
return stdOutput;
}
catch (Exception e)
{
throw new Exception("Encountered unexpected error while running pod", e);
}
}
}
}
}
【问题讨论】:
-
Process类没有实现IDisposable接口。