visual-studio 编辑 sln、proj、suo 文件的最佳实践?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3877290/
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-10-22 12:33:20  来源:igfitidea点击:

Best practices for editing sln, proj, suo files?

.netvisual-studio

提问by GurdeepS

In .NET, there are SUO, SLN, Proj files for every solution/project. Whilst I know what these files are, is it wise to edit them by hand? Do they ever even need to be edited? If so, what is the best way?

在 .NET 中,每个解决方案/项目都有 SUO、SLN、Proj 文件。虽然我知道这些文件是什么,但手动编辑它们是否明智?他们甚至需要编辑吗?如果是这样,最好的方法是什么?

Thanks

谢谢

采纳答案by zainnab

You can edit many of the files available. There are even instructions for doing it in the documentation http://msdn.microsoft.com/en-us/library/ms171487(v=VS.90).aspx

您可以编辑许多可用的文件。在文档http://msdn.microsoft.com/en-us/library/ms171487(v=VS.90).aspx中甚至有关于这样做的说明

Solution files are NOT in XML format and you can find information on the content of .SLN files here: https://msdn.microsoft.com/en-us/library/bb165951(v=vs.140).aspx

解决方案文件不是 XML 格式,您可以在此处找到有关 .SLN 文件内容的信息:https://msdn.microsoft.com/en-us/library/bb165951(v =vs.140).aspx

Project files are MSBuild scripts so they are frequently edited (either with a tool or manually) to include items that modify the build configuration to meet your needs. Here is a link to the MSBuild reference that may help: http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx

项目文件是 MSBuild 脚本,因此它们经常被编辑(使用工具或手动)以包含修改构建配置以满足您的需求的项目。以下是可能有帮助的 MSBuild 参考链接:http: //msdn.microsoft.com/en-us/library/0k6kkbsd.aspx

.SUO files are your user options and shouldn't be edited directly. I have personally used the binary editor and edited it just to see if it can be done with success but you do so at your own risk.

.SUO 文件是您的用户选项,不应直接编辑。我个人使用了二进制编辑器并对其进行了编辑,只是为了看看它是否可以成功完成,但这样做的风险由您自己承担。

回答by adrianbanks

The project files can easily be edited by hand - you have to do it sometimes to add items to the project that MSBuild supports but Visual Studio does not support the editing of (such as conditional elements). I have an add-in for Visual Studio (I think it might be PowerCommands) that adds an "Edit project file" option to the context menu in Solution Explorer. Clicking it unloads the project from Visual Studio and opens the prof file as XML to be edited in Visual Studio's XML editor.

可以轻松地手动编辑项目文件 - 有时您必须这样做才能将项目添加到 MSBuild 支持但 Visual Studio 不支持编辑的项目(例如条件元素)。我有一个 Visual Studio 插件(我认为它可能是 PowerCommands),它在解决方案资源管理器的上下文菜单中添加了一个“编辑项目文件”选项。单击它会从 Visual Studio 中卸载项目,并以 XML 格式打开 prof 文件,以便在 Visual Studio 的 XML 编辑器中进行编辑。

The SLN files are not XML, but they do not really contain anything that would be worth editing by hand.

SLN 文件不是 XML,但它们实际上并不包含任何值得手动编辑的内容。

I think the SUO files are binary and shouldn't be edited (they only contain user-specific values for the solution).

我认为 SUO 文件是二进制文件,不应编辑(它们仅包含解决方案的用户特定值)。

回答by jnielsen

When editing the project files, you can right-click the project in Visual Studio, and choose Unload Project. You can then right-click the same project (now greyed out) and choose edit. Once, complete, again right-click and choose Reload.

编辑工程文件时,可以在Visual Studio中右键工程,选择Unload Project。然后,您可以右键单击同一个项目(现在变灰)并选择编辑。一次,完成,再次右键单击并选择重新加载。

回答by Steven Sudit

Sure, I occasionally have the need to edit them. Recently, I had a project file that had the flag enabled to register the assembly as a COM object. After I removed all COM-visible classes, this generated a warning, so I removed that line from the project file. I used Notepad.

当然,我偶尔需要编辑它们。最近,我有一个项目文件,该文件启用了将程序集注册为 COM 对象的标志。删除所有 COM 可见类后,这会生成一个警告,因此我从项目文件中删除了该行。我用的是记事本。

回答by Aaron McIver

Have to edit them very rarely. One case was modification of the ProjectTypeGuids, so that it was recognized properly in Expression Blend. Couple of other times had to make some manual changes to references no longer existent.

必须很少编辑它们。一种情况是修改了 ProjectTypeGuids,以便在 Expression Blend 中正确识别它。其他几次不得不对不再存在的引用进行一些手动更改。

All in all it has been few and far between. The .prj files are XML so any good XML editor would suffice. The properties page in VS obviously references the .prj file as well for changes not wanting to be made by hand.

总而言之,它已经很少了。.prj 文件是 XML,所以任何好的 XML 编辑器就足够了。VS 中的属性页面显然也引用了 .prj 文件,以用于不想手动进行的更改。

回答by cristobalito

I've never had to edit a SUO file - not even sure what it does.

我从未编辑过 SUO 文件 - 甚至不确定它的作用。

With respect to .sln and .proj files, they are certainly editable by hand, but for anything complicated, I find it'd better to let VS do the hard work, followed by surgical editing of the files as required.

对于 .sln 和 .proj 文件,它们当然可以手动编辑,但对于任何复杂的事情,我发现最好让 VS 完成艰苦的工作,然后根据需要对文件进行外科编辑。

One thing that's made a lot of difference in my place of work is the adoption of PropertySheetsto define a common set of settings across different projects.

对我的工作场所产生很大影响的一件事是采用PropertySheets来定义跨不同项目的一组通用设置。

回答by softveda

Many of our csproj files are edited for using advanced msbuild features. One common thing is to change the beforebuild and afterbuild targets for custom tasks.
You can do this from visual studio by right clicking on a project and selecting unload project from the context menu. After that you can edit and reload the project using right click again.

我们的许多 csproj 文件都经过编辑以使用高级 msbuild 功能。一件常见的事情是更改自定义任务的 beforebuild 和 afterbuild 目标。
您可以在 Visual Studio 中通过右键单击项目并从上下文菜单中选择卸载项目来执行此操作。之后,您可以再次使用右键单击来编辑和重新加载项目。