Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the contents of the configuration file I used to support both .NET 2.0 and .NET 4 assemblies:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;!-- http://msdn.microsoft.com/en-us/library/w4atty68.aspx --&gt; &lt;startup useLegacyV2RuntimeActivationPolicy="true"&gt; &lt;supportedRuntime version="v4.0" /&gt; &lt;supportedRuntime version="v2.0.50727" /&gt; &lt;/startup&gt; &lt;/configuration&gt; </code></pre> <p>Also, here’s a simplified version of the PowerShell 1.0 compatible code I used to execute our scripts from the passed in command line arguments:</p> <pre><code>class Program { static void Main( string[] args ) { Console.WriteLine( ".NET " + Environment.Version ); string script = "&amp; " + string.Join( " ", args ); Console.WriteLine( script ); Console.WriteLine( ); // Simple host that sends output to System.Console PSHost host = new ConsoleHost( this ); Runspace runspace = RunspaceFactory.CreateRunspace( host ); Pipeline pipeline = runspace.CreatePipeline( ); pipeline.Commands.AddScript( script ); try { runspace.Open( ); IEnumerable&lt;PSObject&gt; output = pipeline.Invoke( ); runspace.Close( ); // ... } catch( RuntimeException ex ) { string psLine = ex.ErrorRecord.InvocationInfo.PositionMessage; Console.WriteLine( "error : {0}: {1}{2}", ex.GetType( ), ex.Message, psLine ); ExitCode = -1; } } } </code></pre> <p>In addition to the basic error handling shown above, we also inject a <code>trap</code> statement into the script to display additional diagnostic information (similar to Jeffrey Snover's <a href="http://blogs.msdn.com/b/powershell/archive/2006/12/07/resolve-error.aspx" rel="nofollow noreferrer">Resolve-Error</a> function).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload