Exemple #1
0
        public override ImmutableArray <MSBuildInstance> GetInstances()
        {
#if NETCOREAPP
            const string DotNetSdkVersion = "6.0.100";

            // Restrict instances to NET 6 SDK
            var instances = MicrosoftBuildLocator.QueryVisualStudioInstances()
                            .Where(instance => instance.Version.ToString() == DotNetSdkVersion)
                            .ToImmutableArray();

            if (instances.Length == 0)
            {
                Logger.LogError($"OmniSharp requires .NET SDK version '{DotNetSdkVersion}' be installed. Please visit https://dotnet.microsoft.com/download/dotnet/6.0 to download the .NET SDK.");
            }
#else
            if (!PlatformHelper.IsWindows)
            {
                return(NoInstances);
            }

            var instances = MicrosoftBuildLocator.QueryVisualStudioInstances();
#endif

            return(instances.Select(instance =>
            {
                var microsoftBuildPath = Path.Combine(instance.MSBuildPath, "Microsoft.Build.dll");
                var version = GetMSBuildVersion(microsoftBuildPath);

                return new MSBuildInstance(
                    $"{instance.Name} {instance.Version}",
                    instance.MSBuildPath,
                    version,
                    GetDiscoveryType(instance.DiscoveryType));
            }).ToImmutableArray());
Exemple #2
0
 public MSBuildContextTests()
 {
     // Need to register MSBuild libraries before using them.
     if (MicrosoftBuildLocator.CanRegister)
     {
         MicrosoftBuildLocator.RegisterDefaults();
     }
 }
        public void RegisterInstance(MSBuildInstance instance)
        {
            if (RegisteredInstance != null)
            {
                throw new InvalidOperationException("An MSBuild instance is already registered.");
            }

            RegisteredInstance = instance ?? throw new ArgumentNullException(nameof(instance));

            if (instance.SetMSBuildExePathVariable)
            {
                var msbuildExePath = Path.Combine(instance.MSBuildPath, "MSBuild.exe");
                var msbuildDllPath = Path.Combine(instance.MSBuildPath, "MSBuild.dll");

                string msbuildPath = null;
                if (File.Exists(msbuildExePath))
                {
                    msbuildPath = msbuildExePath;
                }
                else if (File.Exists(msbuildDllPath))
                {
                    msbuildPath = msbuildDllPath;
                }

                if (!string.IsNullOrEmpty(msbuildPath))
                {
                    Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", msbuildPath);
                    _logger.LogInformation($"MSBUILD_EXE_PATH environment variable set to '{msbuildPath}'");
                }
                else
                {
                    _logger.LogError("Could not find MSBuild executable path.");
                }
            }

            var builder = new StringBuilder();

            builder.Append($"Registered MSBuild instance: {instance}");

            foreach (var kvp in instance.PropertyOverrides)
            {
                builder.Append($"{Environment.NewLine}            {kvp.Key} = {kvp.Value}");
            }

            _logger.LogInformation(builder.ToString());

            if (!MicrosoftBuildLocator.CanRegister)
            {
                return;
            }

            MicrosoftBuildLocator.RegisterMSBuildPath(instance.MSBuildPath);
        }
        public override ImmutableArray <MSBuildInstance> GetInstances()
        {
            if (!PlatformHelper.IsWindows)
            {
                return(NoInstances);
            }

            return(MicrosoftBuildLocator.QueryVisualStudioInstances()
                   .Select(instance =>
            {
                var microsoftBuildPath = Path.Combine(instance.MSBuildPath, "Microsoft.Build.dll");
                var version = GetMSBuildVersion(microsoftBuildPath);

                return new MSBuildInstance(
                    $"{instance.Name} {instance.Version}",
                    instance.MSBuildPath,
                    version,
                    GetDiscoveryType(instance.DiscoveryType));
            }).ToImmutableArray());