Exemplo n.º 1
0
        public static MSBuildInstance AddDotNetCoreToFakeInstance(this MSBuildInstance instance)
        {
            const string dotnetSdkResolver = "Microsoft.DotNet.MSBuildSdkResolver";

            var directory = Path.Combine(
                instance.MSBuildPath,
                "SdkResolvers",
                dotnetSdkResolver
                );

            Directory.CreateDirectory(directory);

            TestIO.TouchFakeFile(Path.Combine(directory, dotnetSdkResolver + ".dll"));

            return(instance);
        }
Exemplo n.º 2
0
        private static MSBuildInstance AskWhichVisualStudioInstanceToUse(List <MSBuildInstance> instances)
        {
            if (instances.Count == 0)
            {
                Console.WriteLine("MSBuild not found! Exiting.");
                Environment.Exit(-1);
            }

            for (var i = 1; i <= instances.Count; i++)
            {
                var instance    = instances[i - 1];
                var recommended = string.Empty;

                // The dev console is probably always the right choice because the user explicitly opened
                // one associated with a Visual Studio install. It will always be first in the list.
                if (instance.DiscoveryType == DiscoveryType.DeveloperConsole)
                {
                    recommended = " (Recommended!)";
                }

                Console.WriteLine($"{i}) {instance.Name} - {instance.Version}{recommended}");
            }

            Console.WriteLine();
            Console.WriteLine("Select an instance of MSBuild: ");
            var             answer       = Console.ReadLine();
            MSBuildInstance instanceUsed = null;

            if (int.TryParse(answer, out int instanceChoice) && instanceChoice > 0 && instanceChoice <= instances.Count)
            {
                instanceUsed = instances[instanceChoice - 1];
            }
            else
            {
                Console.WriteLine($"{answer} is not a valid response.");
                Environment.Exit(-1);
            }

            return(instanceUsed);
        }
Exemplo n.º 3
0
        private static void RegisterMSBuildInstance(IMSBuildLocator msbuildLocator, ILogger logger)
        {
            MSBuildInstance instanceToRegister = null;
            var             invalidVSFound     = false;

            foreach (var instance in msbuildLocator.GetInstances())
            {
                if (instance.IsInvalidVisualStudio())
                {
                    invalidVSFound = true;
                }
                else
                {
                    instanceToRegister = instance;
                    break;
                }
            }


            if (instanceToRegister != null)
            {
                // Did we end up choosing the standalone MSBuild because there was an invalid Visual Studio?
                // If so, provide a helpful message to the user.
                if (invalidVSFound && instanceToRegister.DiscoveryType == DiscoveryType.StandAlone)
                {
                    logger.LogWarning(@"It looks like you have Visual Studio 2017 RTM installed.
Try updating Visual Studio 2017 to the most recent release to enable better MSBuild support.");
                }

                msbuildLocator.RegisterInstance(instanceToRegister);
            }
            else
            {
                logger.LogError("Could not locate MSBuild instance to register with OmniSharp");
            }
        }
Exemplo n.º 4
0
 public void RegisterInstance(MSBuildInstance instance)
 => RegisteredInstance = instance;
Exemplo n.º 5
0
 public static bool IsInvalidVisualStudio(this MSBuildInstance instance)
 // MSBuild from Visual Studio 2017 RTM cannot be used.
 => instance.Version.Major == 15 &&
 instance.Version.Minor == 0 &&
 (instance.DiscoveryType == DiscoveryType.DeveloperConsole ||
  instance.DiscoveryType == DiscoveryType.VisualStudioSetup);