windows Visual Studio 忘记了窗口设置并弄得一团糟

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/866820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:21:10  来源:igfitidea点击:

Visual studio forgets window settings and makes a mess

windowsvisual-studiodock

提问by cbp

I have this problem where I open Visual Studio and the internal windows are scattered all over the place. None of them are docked; some that should be visible have become invisible and vice versa. I then have to spend ages getting the windows back where I like them.

我在打开 Visual Studio 时遇到了这个问题,并且内部窗口散落在各处。它们都没有停靠;一些应该可见的变得不可见,反之亦然。然后我必须花很长时间把窗户弄回我喜欢的地方。

It only seems to happen with some solutions and only appeared recently.

它似乎只发生在某些解决方案中,并且最近才出现。

For the life of me I can't fix the problem. Has anyone else been through this?

对于我的生活,我无法解决这个问题。有没有其他人经历过这个?

回答by Peter McG

Sounds like there is definitely a problem with Visual Studio retaining your settings between round-trips and possibly your Visual Studio settings profile in general.

听起来 Visual Studio 在往返之间保留您的设置肯定存在问题,并且通常可能是您的 Visual Studio 设置配置文件。

The solution I'd recommend is firstly to reset all settings, secondly customize things to your personal preference and finally take a backup of those customized settings. The idea is that this settings backup file can be used later to automate a quick settings restore to a point you are happy with. The following steps show how to do this and hopefully should sort out even the most confused Visual Studio setting issues:

我推荐的解决方案是首先重置所有设置,其次根据您的个人喜好自定义内容,最后备份这些自定义设置。这个想法是以后可以使用此设置备份文件将快速设置恢复到您满意的程度。以下步骤显示了如何执行此操作,希望能够解决最令人困惑的 Visual Studio 设置问题:

  1. Close down all instances of Visual Studio.

  2. Go to Start > Programs > Visual Studio 200X > Visual Studio Tools > and choose 'Visual Studio 200X Command Prompt'

  3. Run the sligthly less well known 'devenv.exe /ResetUserData' command. With this command you will lose all of your Visual Studio environment settings and customizations. Because of this, the /ResetUserData switch is not officially supported and Microsoft does not advertise it (the switch is not described in the help for devenv.exe you get when you type devenv.exe /? in a command prompt). Importantly, wait for the resulting devenv.exe process to disappear from Task Manager or even better Process Explorer.

  4. When the process disappears from Task Manager or Process Explorer, run 'devenv.exe /ResetSettings' which will restore the IDE's default settings and eventually start a single instance of Visual Studio.

  5. Now in Visual Studio choose 'Import and Export Settings...' near the bottom of the 'Tools' menu to start the Import and Export Settings Wizard.

  6. Choose 'Reset all settings' radio button and Next > Choose 'No, just reset settings, overwriting my current settings' and Next > Choose your personal 'Settings Collection' preference, I would choose Visual C# Development Settings here (Note: What you choose here has an effect on keyboard shortcuts etc. but you can always repeat this process until happy) and click Finish.

  7. When you get the message that 'Your settings were successfully reset to XXXXXX Development Settings.' click Close then spend a good bit of time adding any personal customizations to Visual Studio such as opening windows you always want open, customizing toolbars and adding any toolbar buttons etc.

  8. When you are finished with your personal customization and completely happy with your setup go again to Tools > 'Import and Export Settings...'

  9. Choose 'Export selected environment settings' radio button and Next > Tick 'All Settings' and Next > Choose a file name and directory and click Finish to store a backup of your current settings in a .vssettings file.

  10. In future if things go haywire again head back to Tools > 'Import and Export Settings...' and this time choose 'Import selected environment settings' radio button and Next > Choose 'No, just import new settings, overwriting my current settings' and Next > Either choose the name of your .vssettings file from the list (usually under the My Settings folder) or Browse.. to where you saved the file and Next > Tick 'All Settings' and click Finish.

  11. Importantly, close the single instance of Visual Studio. Any future instance you open should retain your latest customizations.

  1. 关闭 Visual Studio 的所有实例。

  2. 转到开始 > 程序 > Visual Studio 200X > Visual Studio 工具 > 并选择“Visual Studio 200X 命令提示符”

  3. 运行不太为人所知的“devenv.exe /ResetUserData”命令。使用此命令,您将丢失所有 Visual Studio 环境设置和自定义。因此,官方不支持 /ResetUserData 开关,Microsoft 也没有宣传它(在命令提示符下键入 devenv.exe /? 时,您获得的 devenv.exe 帮助中未描述该开关)。重要的是,等待生成的 devenv.exe 进程从任务管理器或更好的进程资源管理器中消失。

  4. 当进程从任务管理器或进程资源管理器中消失时,运行“devenv.exe /ResetSettings”,这将恢复 IDE 的默认设置并最终启动 Visual Studio 的单个实例。

  5. 现在在 Visual Studio 中,选择靠近“工具”菜单底部的“导入和导出设置...”以启动导入和导出设置向导。

  6. 选择“重置所有设置”单选按钮,然后选择“不,只重置设置,覆盖我当前的设置”和“下一步”>“选择您个人的“设置集合”首选项,我会在这里选择 Visual C# 开发设置(注意:您选择的是什么此处对键盘快捷键等有影响,但您始终可以重复此过程直到满意为止)并单击“完成”。

  7. 当您收到“您的设置已成功重置为 XXXXXX 开发设置”的消息时。单击“关闭”,然后花大量时间向 Visual Studio 添加任何个人自定义设置,例如打开您始终希望打开的窗口、自定义工具栏和添加任何工具栏按钮等。

  8. 当您完成您的个人定制并对您的设置完全满意后,再次转到“工具”>“导入和导出设置...”

  9. 选择“导出选定的环境设置”单选按钮和下一步 > 勾选“所有设置”和下一步 > 选择文件名和目录,然后单击完成以将当前设置的备份存储在 .vssettings 文件中。

  10. 将来如果事情再次出问题,请返回工具>“导入和导出设置...”,这次选择“导入选定的环境设置”单选按钮和下一步>选择“不,只导入新设置,覆盖我当前的设置”和下一步 > 从列表中选择 .vssettings 文件的名称(通常在我的设置文件夹下)或浏览.. 到您保存文件的位置,然后下一步 > 勾选“所有设置”并单击完成。

  11. 重要的是,关闭 Visual Studio 的单个实例。您以后打开的任何实例都应保留最新的自定义设置。

回答by Tim Scarborough

I had a similar issue when the My Documents folder was stored on a mapped drive. If I opened VS before mapping the drive, VS would act as if it was the first time it had been opened. I solved this issue by storing the environment settings on the local disk.

当我的文档文件夹存储在映射驱动器上时,我遇到了类似的问题。如果我在映射驱动器之前打开 VS,VS 会表现得好像它是第一次打开一样。我通过将环境设置存储在本地磁盘上解决了这个问题。

回答by Jason Williams

Visual Studio corrupts its settings with regular monotony (always has done, I've been suffering from this since the Visual C++ days, and it's still a bugbear in VS2013).

Visual Studio 用常规的单调破坏了它的设置(总是如此,从 Visual C++ 时代起我就一直受此困扰,而且它在 VS2013 中仍然是一个bugbear)。

Often this seems to be totally at random, but it's highly probable after a crash.

通常这似乎是完全随机的,但在崩溃后很有可能。

It will also lose any changes to your settings if Visual Studio doesn't shut down cleanly - for some reason instead of saving back the settings when you OK the dialog, VS seems to wait until it quits to write back your changes, so after changing options I always quit and restart to ensure the changes have been flushed to disk. Similarly you should never change options with 2 or more instances of VS running, as the last one to quit will overwrite the settings.

如果 Visual Studio 没有完全关闭,它也会丢失对您的设置的任何更改 - 由于某种原因,而不是在您确定对话框时保存设置,VS 似乎等到它退出才写回您的更改,因此在更改之后选项我总是退出并重新启动以确保更改已刷新到磁盘。同样,在运行 2 个或更多 VS 实例时,您永远不应更改选项,因为最后一个退出将覆盖设置。

In particular, there is an easily reproducible case: If you launch two or more copies at the same time (by which I mean if you start up two or more copies, so they are all initialising at the same time), they seem to fight over the settings file and it becomes corrupted or resets to defaults.

特别是,有一个很容易重现的情况:如果你同时启动两个或更多副本(我的意思是如果你启动两个或更多副本,所以它们都在同一时间初始化),它们似乎在打架在设置文件上,它会损坏或重置为默认值。

The best two workarounds I've found are:

我发现的最好的两种解决方法是:

  • Never launch more than one instance at a time. If you need to run several instances concurrently, then wait for the first one to finish loading its Solution before you start to launch the next.

  • Always use Tools > Import and Export Settingsto save your settings to a backup file, so that recovering from this corruption only takes a few seconds each time it happens.

  • 切勿一次启动多个实例。如果您需要同时运行多个实例,请等待第一个实例完成加载其解决方案,然后再开始启动下一个。

  • 始终使用Tools > Import and Export Settings将您的设置保存到备份文件,这样每次发生损坏时只需几秒钟即可从损坏中恢复。

Another smaller, but still rather irritating habit is that if VS is minimised when it is quit (e.g. by shutting down), it corrupts its window position information and the next time you run it, it will be maximised.

另一个较小但仍然相当恼人的习惯是,如果 VS 在退出时被最小化(例如通过关闭),它会破坏其窗口位置信息,而在您下次运行它时,它将被最大化。

回答by user1331100

I just ran into this problem too (seemed to trigger after a windows update) where I kept getting some bogus window layout no matter what I did. The above suggestions didn't work either. But luckily the suggestions in: Why doesn't VS 2008 IDE remember my preferences?of deleting:

我也遇到了这个问题(似乎在 Windows 更新后触发),无论我做什么,我都会得到一些虚假的窗口布局。上述建议也没有奏效。但幸运的是以下建议:为什么 VS 2008 IDE 不记得我的偏好?删除:

%APPDATA%\Application Data\Microsoft\VisualStudio.0\windows.prf

worked.

工作。

TP

TP

回答by cbp

Actually I worked out what the culprit was: previous VS crashes.

实际上,我找出了罪魁祸首:之前的 VS 崩溃。

If one of my Visual Studio instances crashes for whatever reason - the next time I start up VS, I get a weird batch of settings. The behaviour depends on various factors, like whether or not I had other instances of VS open at the time.

如果我的一个 Visual Studio 实例因任何原因崩溃 - 下次我启动 VS 时,我会得到一组奇怪的设置。行为取决于各种因素,例如我当时是否打开了其他 VS 实例。

回答by Christopher Nourse

I tried Peter McG's solution, still didn't help. What ended up working for me was to delete my VS Solution User Options (.sou). Located in the same directory as my solution.

我尝试了 Peter McG 的解决方案,但仍然没有帮助。最终对我有用的是删除我的 VS 解决方案用户选项 (.sou)。与我的解决方案位于同一目录中。

Only bad thing is you have to redo all of your settings. This included my exception changes. Not to much to change, but if you have a lot of customization it could be a real pain. There must be something in that file messing everything up, but deleting the whole file is quick and easy.

唯一不好的是您必须重做所有设置。这包括我的异常更改。没有太多改变,但如果你有很多定制,这可能是一个真正的痛苦。该文件中一定有什么东西把一切搞砸了,但删除整个文件既快捷又容易。

回答by Dan Loughney

My issue is similar, but the result is the app crashes. The problem was this value

我的问题类似,但结果是应用程序崩溃。问题是这个值

In HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\MainWindow. It was set to "0 1000 -280 -100 3" probably due to having multiple screens and moving the UI around a lot.

在 HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\MainWindow 中。它被设置为“0 1000 -280 -100 3”可能是因为有多个屏幕和移动用户界面很多。

Deleting this value allowed the app to restart successfully. It gets recreated on startup.

删除此值允许应用程序成功重新启动。它在启动时重新创建。

回答by Josh

Which solution you're opening shouldn't matter because those settings are not solution-specific. But I wonder do you maybe have Visual Studio 2005 and 2008 installed? If so, opening a solution created in 2005 will open VS 2005 and opening a 2008 solution will open VS 2008. You may have VS 2005 even if you didn't install it. For example, InfoPath 2007 installs a VS 2005 shell.

您打开哪个解决方案并不重要,因为这些设置不是特定于解决方案的。但我想知道您是否安装了 Visual Studio 2005 和 2008?如果是这样,打开 2005 年创建的解决方案将打开 VS 2005,打开 2008 解决方案将打开 VS 2008。即使您没有安装 VS 2005,您也可能拥有 VS 2005。例如,InfoPath 2007 安装了一个 VS 2005 shell。

First I would position the windows where you want them, then do a Tools -> Export Settings and include only the window layouts. That way you at least have something you can revert to.

首先,我会将窗口放置在您想要的位置,然后执行“工具”->“导出设置”并仅包含窗口布局。这样你至少有一些你可以恢复的东西。

Then I would check Tools -> Options -> Import Export Settings and make note of where the "Automatically Save My Settings To This File" path is set to. Keep an eye on that file. Do you have any sync software that may be inadvertently overwriting it? Does it point to a non-existing location?

然后我会检查工具 -> 选项 -> 导入导出设置并记下“自动将我的设置保存到此文件”路径的设置位置。留意那个文件。您是否有任何可能无意中覆盖它的同步软件?它是否指向一个不存在的位置?

回答by sergiopereira

I'm facing similar issue. And it also only started recently, like, within the last 30 days or so. The only thing I remember changing in this period was updating Resharper 4.5.

我面临类似的问题。而且它也是最近才开始的,例如,在过去 30 天左右的时间内。我记得在此期间唯一改变的是更新 Resharper 4.5。

回答by LucasM

I have experienced something similar. In my case the text editor colors (c# editor for example) are going haywire. The only solution that I tried and works for me is change color theme so something else and then back to what I want.

我也经历过类似的事情。在我的情况下,文本编辑器的颜色(例如 c# 编辑器)正在失控。我尝试过并对我来说有效的唯一解决方案是更改颜色主题,然后再换回我想要的颜色。