Mono.CSharp.Driver.GetPackageFlags C# (CSharp) Method

GetPackageFlags() public static method

public static GetPackageFlags ( string packages, bool fatal, Report report ) : string
packages string
fatal bool
report Report
return string
		public static string GetPackageFlags (string packages, bool fatal, Report report)
		{
			ProcessStartInfo pi = new ProcessStartInfo ();
			pi.FileName = "pkg-config";
			pi.RedirectStandardOutput = true;
			pi.UseShellExecute = false;
			pi.Arguments = "--libs " + packages;
			Process p = null;
			try {
				p = Process.Start (pi);
			} catch (Exception e) {
				report.Error (-27, "Couldn't run pkg-config: " + e.Message);
				if (fatal)
					Environment.Exit (1);
				p.Close ();
				return null;
			}
			
			if (p.StandardOutput == null){
				report.Warning (-27, 1, "Specified package did not return any information");
				p.Close ();
				return null;
			}
			string pkgout = p.StandardOutput.ReadToEnd ();
			p.WaitForExit ();
			if (p.ExitCode != 0) {
				report.Error (-27, "Error running pkg-config. Check the above output.");
				if (fatal)
					Environment.Exit (1);
				p.Close ();
				return null;
			}
			p.Close ();

			return pkgout;
		}

Usage Example

        /// <summary>
        ///   Loads the assemblies from a package
        /// </summary>
        /// <remarks>
        ///   Loads the assemblies from a package.   This is equivalent
        ///   to passing the -pkg: command line flag to the C# compiler
        ///   on the command line.
        /// </remarks>
        static public void LoadPackage(string pkg)
        {
            if (pkg == null)
            {
                Error.WriteLine("Invalid package specified");
                return;
            }

            string pkgout = Driver.GetPackageFlags(pkg, false, RootContext.ToplevelTypes.Compiler.Report);

            if (pkgout == null)
            {
                return;
            }

            string [] xargs = pkgout.Trim(new Char [] { ' ', '\n', '\r', '\t' }).
                              Split(new Char [] { ' ', '\t' });

            foreach (string s in xargs)
            {
                if (s.StartsWith("-r:") || s.StartsWith("/r:") || s.StartsWith("/reference:"))
                {
                    string lib = s.Substring(s.IndexOf(':') + 1);

                    Evaluator.LoadAssembly(lib);
                    continue;
                }
            }
        }
All Usage Examples Of Mono.CSharp.Driver::GetPackageFlags