.net-4.0scriptcs

Can I run scriptcs with useLegacyV2RuntimeActivationPolicy?


I have a DLL (Microsoft.SqlServer.BatchParser) which I need to reference in a scriptcs file.

The following DLL can only be referenced if useLegacyV2RuntimeActivationPolicy is included in the app.config file.

For example, this console application:

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            var batchParser = new ManagedBatchParser.Parser();
        }
    }
}

will only compile if I include useLegacyV2RuntimeActivationPolicy in the app.config like so:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">    
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
</configuration>

But doing the same in a CSX file:

#r "Microsoft.Sqlserver.BatchParser"

var batchParser = new ManagedBatchParser.Parser();  

will fail because I don't know how to specify this attribute. I get the infamous error as soon as I try to run the scriptcs file:

Additional information: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

So my main question is, how can I tell scriptcs to start compiling the CSX file with the useLegacyV2RuntimeActivationPolicy attribute ?


Solution

  • Your app.config file will be renamed to program.exe.config. In order to do this with ScriptCS you just need a file named scriptcs.exe.config that has the useLegacyV2RuntimeActivationPolicy startup node in it.