Exemplo n.º 1
0
        public static void Initialize(ILogger logger)
        {
            if (s_isInitialized)
            {
                throw new InvalidOperationException("MSBuild environment is already initialized.");
            }

            // If MSBuild can locate VS 2017 and set up a build environment, we don't need to do anything.
            // MSBuild will take care of itself.
            if (MSBuildHelpers.CanInitializeVisualStudioBuildEnvironment())
            {
                logger.LogInformation("MSBuild will use local Visual Studio installation.");
                s_usingVisualStudio = true;
                s_isInitialized     = true;
            }
            else if (TryWithLocalMSBuild(logger, out var msbuildExePath, out var msbuildExtensionsPath))
            {
                logger.LogInformation("MSBuild will use local OmniSharp installation.");
                s_msbuildExePath        = msbuildExePath;
                s_msbuildExtensionsPath = msbuildExtensionsPath;
                s_isInitialized         = true;
            }

            if (!s_isInitialized)
            {
                logger.LogError("MSBuild environment could not be initialized.");
            }
        }
Exemplo n.º 2
0
        public static void Initialize(ILogger logger)
        {
            if (s_isInitialized)
            {
                throw new InvalidOperationException("MSBuild environment is already initialized.");
            }

            // If MSBuild can locate VS 2017 and set up a build environment, we don't need to do anything.
            // MSBuild will take care of itself.
            if (MSBuildHelpers.CanInitializeVisualStudioBuildEnvironment())
            {
                s_kind          = MSBuildEnvironmentKind.VisualStudio;
                s_isInitialized = true;
            }
            else if (TryWithMonoMSBuild())
            {
                s_kind          = MSBuildEnvironmentKind.Mono;
                s_isInitialized = true;
            }
            else if (TryWithLocalMSBuild())
            {
                s_kind          = MSBuildEnvironmentKind.StandAlone;
                s_isInitialized = true;
            }
            else
            {
                s_kind = MSBuildEnvironmentKind.Unknown;
                logger.LogError("MSBuild environment could not be initialized.");
                s_isInitialized = false;
            }

            if (!s_isInitialized)
            {
                return;
            }

            var summary = new StringBuilder();

            switch (s_kind)
            {
            case MSBuildEnvironmentKind.VisualStudio:
                summary.AppendLine("OmniSharp initialized with Visual Studio MSBuild.");
                break;

            case MSBuildEnvironmentKind.Mono:
                summary.AppendLine("OmniSharp initialized with Mono MSBuild.");
                break;

            case MSBuildEnvironmentKind.StandAlone:
                summary.AppendLine("Omnisharp will use local MSBuild.");
                break;
            }

            if (s_msbuildExePath != null)
            {
                summary.AppendLine($"    MSBUILD_EXE_PATH: {s_msbuildExePath}");
            }

            if (s_msbuildExtensionsPath != null)
            {
                summary.AppendLine($"    MSBuildExtensionsPath: {s_msbuildExtensionsPath}");
            }

            if (s_targetFrameworkRootPath != null)
            {
                summary.AppendLine($"    TargetFrameworkRootPath: {s_targetFrameworkRootPath}");
            }

            if (s_roslynTargetsPath != null)
            {
                summary.AppendLine($"    RoslynTargetsPath: {s_roslynTargetsPath}");
            }

            if (s_cscToolPath != null)
            {
                summary.AppendLine($"    CscToolPath: {s_cscToolPath}");
            }

            logger.LogInformation(summary.ToString());
        }