Csi.cs 1.9 KB
Newer Older
1 2 3 4
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.IO;
5
using System.Reflection;
6
using Microsoft.CodeAnalysis.Scripting.Hosting;
7

8
namespace Microsoft.CodeAnalysis.CSharp.Scripting.Hosting
9
{
10
    internal static class Csi
11 12 13 14 15 16 17
    {
        private const string InteractiveResponseFileName = "csi.rsp";

        internal static int Main(string[] args)
        {
            try
            {
18 19 20 21
                // Note that AppContext.BaseDirectory isn't necessarily the directory containing csi.exe.
                // For example, when executed via corerun it's the directory containing corerun.
                string csiDirectory = Path.GetDirectoryName(typeof(Csi).GetTypeInfo().Assembly.ManifestModule.FullyQualifiedName);

J
Jared Parsons 已提交
22
                var buildPaths = new BuildPaths(
23
                    clientDir: csiDirectory,
J
Jared Parsons 已提交
24
                    workingDir: Directory.GetCurrentDirectory(),
25
                    sdkDir: RuntimeMetadataReferenceResolver.GetDesktopFrameworkDirectory(),
J
Jared Parsons 已提交
26
                    tempDir: Path.GetTempPath());
27

28
                var compiler = new CSharpInteractiveCompiler(
29
                    responseFile: Path.Combine(csiDirectory, InteractiveResponseFileName),
J
Jared Parsons 已提交
30
                    buildPaths: buildPaths,
T
Tomas Matousek 已提交
31 32
                    args: args,
                    analyzerLoader: new NotImplementedAnalyzerLoader());
33 34 35 36 37

                var runner = new CommandLineRunner(
                    ConsoleIO.Default,
                    compiler,
                    CSharpScriptCompiler.Instance,
38
                    CSharpObjectFormatter.Instance);
39 40

                return runner.RunInteractive();
41 42 43
            }
            catch (Exception ex)
            {
44
                Console.Error.WriteLine(ex.ToString());
45 46 47 48 49
                return 1;
            }
        }
    }
}