public void ResolvePathVsTest() { int foundVersion = 0; int missingVersion = 0; // Try to make this unit test work for 20 years or so (assuming 2 year release cycles). for (int vsMajorVersion = 15; vsMajorVersion <= 25; vsMajorVersion++) { string?vsExePath = VisualStudioUtility.ResolvePath(ver => @"Common7\IDE\DevEnv.exe", vsMajorVersion, vsMajorVersion); string?vsComPath = VisualStudioUtility.ResolvePath(ver => @"Common7\IDE\DevEnv.com", vsMajorVersion, vsMajorVersion); if (File.Exists(vsExePath)) { File.Exists(vsComPath).ShouldBeTrue("DevEnv.com should exist since DevEnv.exe exists."); foundVersion = vsMajorVersion; } else if (string.IsNullOrEmpty(vsExePath)) { missingVersion = vsMajorVersion; } } string?foundVersionPath = VisualStudioUtility.ResolvePath(ver => @"Common7\IDE\DoesNotExist.exe", foundVersion, foundVersion, true); foundVersionPath.ShouldBeNull($"Version {foundVersion} exists, but the requested path doesn't exist."); foundVersionPath = VisualStudioUtility.ResolvePath(ver => @"Common7\IDE\DoesNotExist.exe", foundVersion, foundVersion, false); foundVersionPath.ShouldNotBeNull($"Version {foundVersion} exists, and the path can be resolved (but doesn't exist)."); string?missingVersionPath = VisualStudioUtility.ResolvePath(ver => @"Common7\IDE\DevEnv.exe", missingVersion, missingVersion); missingVersionPath.ShouldBeNull($"Version {missingVersion} doesn't exist."); }
public static Setting Initialize(DTE serviceProvider) { var settings = Instance; if (settings.ServiceProvider == null || settings.ServiceProvider != serviceProvider) { settings.ServiceProvider = serviceProvider; } try { var solfile = VisualStudioUtility.GetSolutionSettingsFileFullPath(); if (!string.IsNullOrWhiteSpace(solfile)) { var solconf = Deserialize(solfile); settings.BackgroundImageAbsolutePath = solconf.BackgroundImageAbsolutePath; settings.BackgroundImagesDirectoryAbsolutePath = solconf.BackgroundImagesDirectoryAbsolutePath; settings.ExpandToIDE = solconf.ExpandToIDE; settings.Extensions = solconf.Extensions; settings.ImageBackgroundType = solconf.ImageBackgroundType; settings.ImageFadeAnimationInterval = solconf.ImageFadeAnimationInterval; settings.ImageStretch = solconf.ImageStretch; settings.LoopSlideshow = solconf.LoopSlideshow; settings.MaxHeight = solconf.MaxHeight; settings.MaxWidth = solconf.MaxWidth; settings.Opacity = solconf.Opacity; settings.PositionHorizon = solconf.PositionHorizon; settings.PositionVertical = solconf.PositionVertical; settings.ShuffleSlideshow = solconf.ShuffleSlideshow; settings.SoftEdgeX = solconf.SoftEdgeX; settings.SoftEdgeY = solconf.SoftEdgeY; settings.UpdateImageInterval = solconf.UpdateImageInterval; settings.ViewBoxPointX = solconf.ViewBoxPointX; settings.ViewBoxPointY = solconf.ViewBoxPointY; settings.SolutionConfigFilePath = solfile; settings.IsLimitToMainlyEditorWindow = solconf.IsLimitToMainlyEditorWindow; settings.TileMode = solconf.TileMode; settings.ViewPortHeight = solconf.ViewPortHeight; settings.ViewPortWidth = solconf.ViewPortWidth; settings.ViewPortPointX = solconf.ViewPortPointX; settings.ViewPortPointY = solconf.ViewPortPointY; settings.WebSingleUrl = solconf.WebSingleUrl; settings.WebApiEndpoint = solconf.WebApiEndpoint; settings.WebApiJsonKey = solconf.WebApiJsonKey; settings.WebApiDownloadInterval = solconf.WebApiDownloadInterval; } else { settings.Load(); } } catch { return(Deserialize()); } return(settings); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); var solconf = VisualStudioUtility.GetSolutionSettingsFileFullPath(); var slideshow = (SlideShowImageProvider)ProvidersHolder.Instance.Providers.FirstOrDefault(p => p.SolutionConfigFile == solconf && p.ProviderType == ImageBackgroundType.Slideshow); slideshow?.NextImage(); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); var solution = VisualStudioUtility.GetSolutionSettingsFileFullPath(false); if (!string.IsNullOrWhiteSpace(solution)) { _setting.Serialize(solution); } }
public void ResolvePathMsBuildTest() { string?msBuildPath = VisualStudioUtility.ResolvePath(version => { string versionPath = version.Major == VisualStudioUtility.VS2017MajorVersion ? $"{VisualStudioUtility.VS2017MajorVersion}.0" : "Current"; return($@"MSBuild\{versionPath}\Bin\Roslyn"); }, VisualStudioUtility.VS2017MajorVersion, resolvedPathMustExist: true); msBuildPath.ShouldNotBeEmpty(); Directory.Exists(msBuildPath).ShouldBeTrue("MSBuild's Roslyn directory must exist."); }
private static void TestOpenFile([CallerFilePath] string?sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = 0) { if (AffectUI && sourceFilePath.IsNotEmpty() && File.Exists(sourceFilePath)) { Process[] processes = Process.GetProcessesByName("DevEnv"); if (processes.Length > 0) { foreach (Process devEnv in processes) { devEnv.Dispose(); } bool opened = VisualStudioUtility.OpenFile(sourceFilePath, sourceLineNumber.ToString()); opened.ShouldBeTrue("Opened in DevEnv"); } } }
private bool TryGetPathFromSetupConfiguration(bool useExe, [MaybeNullWhen(false)] out string devEnvPath) { devEnvPath = VisualStudioUtility.ResolvePath( ver => @"Common7\IDE\DevEnv." + (useExe ? "exe" : "com"), (int)this.InternalVersion, (int)this.InternalVersion); bool result = !string.IsNullOrEmpty(devEnvPath); // This must return a non-null, non-empty path, even if it doesn't exist. VSStep depends on getting back // at least an environment variable-based path that it can display to the user. So we'll make one up here. if (!result) { // Note: "Edition" should actually be Professional, Communitiy, or Enterprise. // But there's no point being specific about a non-installed edition. devEnvPath = $@"{this.ProgramFilesVariable}\Microsoft Visual Studio\{this.DisplayNumber}\[Missing Edition]\Common7\IDE\devenv.exe"; } return(result); }
private SlideShowImageProvider GetSlideshow() { var solconf = VisualStudioUtility.GetSolutionSettingsFileFullPath(); return((SlideShowImageProvider)ProvidersHolder.Instance.Providers.FirstOrDefault(p => p.SolutionConfigFile == solconf && p.ProviderType == ImageBackgroundType.Slideshow)); }