简体   繁体   English

编辑sln,proj,suo文件的最佳实践?

[英]Best practices for editing sln, proj, suo files?

In .NET, there are SUO, SLN, Proj files for every solution/project. 在.NET中,每个解决方案/项目都有SUO,SLN,Proj文件。 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? 如果是这样,最好的方法是什么?

Thanks 谢谢

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. 项目文件是MSBuild脚本,因此经常对它们进行编辑(使用工具或手动编辑),以包含修改构建配置以满足您需求的项目。 Here is a link to the MSBuild reference that may help: http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx 以下是可能有用的MSBuild参考链接: http//msdn.microsoft.com/en-us/library/0k6kkbsd.aspx

.SUO files are your user options and shouldn't be edited directly. .SUO文件是您的用户选项,不应直接编辑。 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. 我亲自使用了二进制编辑器并对其进行了编辑,以确定它是否可以成功完成,但您需要自己承担风险。

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 ). 可以手动编辑项目文件 - 有时您必须将项目添加到MSBuild支持的项目中,但Visual Studio不支持编辑(例如条件元素 )。 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. 我有一个Visual Studio加载项(我认为它可能是PowerCommands),它在解决方案资源管理器中的上下文菜单中添加了一个“编辑项目文件”选项。 Clicking it unloads the project from Visual Studio and opens the prof file as XML to be edited in Visual Studio's XML editor. 单击它从Visual Studio卸载项目,并将Prof文件作为XML打开,以便在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文件是二进制文件,不应编辑(它们只包含解决方案的用户特定值)。

When editing the project files, you can right-click the project in Visual Studio, and choose Unload Project. 编辑项目文件时,可以在Visual Studio中右键单击项目,然后选择“卸载项目”。 You can then right-click the same project (now greyed out) and choose edit. 然后,您可以右键单击同一项目(现在显示为灰色)并选择编辑。 Once, complete, again right-click and choose Reload. 完成后,再次右键单击并选择“重新加载”。

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. 最近,我有一个项目文件,该文件启用了标志,将程序集注册为COM对象。 After I removed all COM-visible classes, this generated a warning, so I removed that line from the project file. 删除所有COM可见类后,这会生成警告,因此我从项目文件中删除了该行。 I used Notepad. 我用过记事本。

Have to edit them very rarely. 必须很少编辑它们。 One case was modification of the ProjectTypeGuids, so that it was recognized properly in Expression Blend. 一个案例是修改ProjectTypeGuids,以便在Expression Blend中正确识别它。 Couple of other times had to make some manual changes to references no longer existent. 其他几次不得不对不再存在的引用进行一些手动更改。

All in all it has been few and far between. 总而言之,它几乎没有。 The .prj files are XML so any good XML editor would suffice. .prj文件是XML,因此任何好的XML编辑器就足够了。 The properties page in VS obviously references the .prj file as well for changes not wanting to be made by hand. VS中的属性页面显然也引用了.prj文件以及不希望手动创建的更改。

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 PropertySheets to define a common set of settings across different projects. 在我的工作场所产生很大不同的一件事是采用PropertySheets来定义不同项目的一组通用设置。

Many of our csproj files are edited for using advanced msbuild features. 我们的许多csproj文件都是使用高级msbuild功能进行编辑的。 One common thing is to change the beforebuild and afterbuild targets for custom tasks. 一个常见的事情是更改自定义任务的beforebuild和afterbuild目标。
You can do this from visual studio by right clicking on a project and selecting unload project from the context menu. 您可以通过右键单击项目并从上下文菜单中选择卸载项目,从visual studio执行此操作。 After that you can edit and reload the project using right click again. 之后,您可以再次右键单击编辑和重新加载项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM