public static void EnsureMaxVisualStudioMsBuildVersionHasBeenRegistered()
        {
            try
            {
                if (MaxVisualStudionVersionHasBeenRegistered)
                {
                    return;
                }

                lock (MaxVisualStudionVersionRegistrationLock)
                {
                    if (MaxVisualStudionVersionHasBeenRegistered)
                    {
                        return;
                    }

                    var maxVisualStudioInstance = MSBuildLocator
                                                  .QueryVisualStudioInstances()
                                                  .OrderByDescending(x => x.Version.Major)
                                                  .First();

                    MSBuildLocator.RegisterInstance(maxVisualStudioInstance);

                    MaxVisualStudionVersionHasBeenRegistered = true;

                    DteUtil.WriteExtensionOutput($"Using msbuild version from Visual Studio version {maxVisualStudioInstance.Version}, " +
                                                 $"path: {maxVisualStudioInstance.MSBuildPath}");
                }
            }
            catch (Exception ex)
            {
                DteUtil.WriteExtensionOutput($"Error during Visual Studio msbuild registration. {ex.Message}");
            }
        }
Beispiel #2
0
        internal static void EnsureSelectedProjReferencesAreLoadedCommand(IServiceProvider provider, bool unloadUnusedProjects)
        {
            var dte = Package.GetGlobalService(typeof(DTE)) as DTE;

            foreach (string projectName in DteUtil.GetSelectedItemNames(dte))
            {
                LoadProject(dte, projectName);
            }
        }
        public async Task <HashSet <string> > GetRecursivelyReferencedProjectsAsync(DTE dte, string[] rootProjectNames)
        {
            var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));
            var workspace      = componentModel.GetService <Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>();

            DteUtil.LoadProject(dte, rootProjectNames[0]);

            //var workspace = MSBuildWorkspace.Create();

            //var solution = workspace.OpenSolutionAsync(solutionFilePath).Result;
            var solution = workspace.CurrentSolution;

            var references = new ConcurrentDictionary <string, object>();

            var tasks = rootProjectNames
                        .Select(async(projName) =>
            {
                await FillReferencedProjectSetRecursivelyAsync(solution, projName, references);
            });

            await Task.WhenAll(tasks);

            return(new HashSet <string>(references.Keys));
        }