C# 为什么“设置为启动”选项存储在 suo 文件而不是 sln 文件中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/694730/
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
Why is "Set as Startup" option stored in the suo file and not the sln file?
提问by leora
It seems like this setting should be stored in the solution file so it's shared across all users and part of source code control. Since we don't check in the suo file, each user has to set this separately which seems strange.
似乎此设置应该存储在解决方案文件中,以便在所有用户和源代码控制的一部分之间共享。由于我们不签入 suo 文件,因此每个用户都必须单独设置它,这看起来很奇怪。
采纳答案by Jon Skeet
Why should it be a non-user-specific preference?
为什么它应该是非用户特定的偏好?
If I've got a solution with 10 files in, and one developer is primarily testing/using one of those tools, why should that affect what I start up?
如果我有一个包含 10 个文件的解决方案,并且一名开发人员主要测试/使用其中一种工具,为什么这会影响我的启动?
I think MS made the right choice on this one. The project Iwant to start is far from necessarily the project that otherdevelopers want to start.
我认为 MS 在这一点上做出了正确的选择。这个项目我想开始是远远一定的项目其他开发商要启动。
回答by Wim Hollebrandse
In most cases, it doesmake sense to have a default on this.
在大多数情况下,对此设置默认值确实有意义。
It would be much better to accommodate a default startup project and store this in the .sln file, but which can be overridden by a developer in their .suo file. If the startup setting isn't found in the .suo file, the default startup project in the .sln would be used.
容纳默认启动项目并将其存储在 .sln 文件中会好得多,但开发人员可以在其 .suo 文件中覆盖它。如果在 .suo 文件中找不到启动设置,则将使用 .sln 中的默认启动项目。
Actually, this has been suggested on Visual Studio's UserVoice.
回答by Oliver
It is absolutely necessary that everyone can define their StartUp Project themselves, as Jon has already said. But to have a dedicated default one would be great, and as I can tell, it is possible!
正如Jon 已经说过的,每个人都可以自己定义他们的 StartUp Project 是绝对必要的。但是拥有一个专用的默认值会很棒,而且据我所知,这是可能的!
If you don't have a .suo file in your solution directory, Visual Studio picks the first project in your .sln file as the default startup project.
如果解决方案目录中没有 .suo 文件,Visual Studio 会选择 .sln 文件中的第一个项目作为默认启动项目。
Close your Visual Studio and open the .sln file in your favorite text editor. Starting in line 4, you see all your projects encapsulated in
Project
–EndProject
lines.Cut and paste the desired default startup project to the top position.
Delete your .suo file.
Open your solution in Visual Studio. Ta daa!
关闭 Visual Studio 并在您喜欢的文本编辑器中打开 .sln 文件。从第 4 行开始,您会看到所有项目都封装在
Project
–EndProject
行中。将所需的默认启动项目剪切并粘贴到顶部位置。
删除您的 .suo 文件。
在 Visual Studio 中打开您的解决方案。哒哒!
Is there a special award if you know something that Jon doesn't know?;-)
如果您知道乔恩不知道的事情,是否有特别奖励?;-)
回答by michaK
I wrote a little command line utility for Windows called slnStartupProject
to set the Startup Project automatically:
我为 Windows 编写了一个小命令行实用程序,用于slnStartupProject
自动设置启动项目:
slnStartupProject slnFilename projectName
I personally use it to set the startup project after generating the solution with cmakethat always sets a dummy ALL_BUILD
project as the first project in the solution.
我个人在使用cmake生成解决方案后使用它来设置启动项目,该解决方案始终将一个虚拟ALL_BUILD
项目设置为解决方案中的第一个项目。
The sourceis on GitHub. Forks and feedback are welcome.
该源是在GitHub上。欢迎分叉和反馈。
回答by sebetovsky
If you are using GIT, you can commit the default SUO file and then mark it as unchanged using
如果您使用的是 GIT,您可以提交默认的 SUO 文件,然后使用
git update-index --assume-unchanged YourSolution.suo
It works also if you want to have more than one project in your default start group. The only disadvantage that I know about is that this command must be run by everyone who don't want to commit the SUO file.
如果您想在默认启动组中拥有多个项目,它也适用。我所知道的唯一缺点是此命令必须由不想提交 SUO 文件的每个人运行。