在.sln文件中注释行

9
我试图在.sln文件中临时评论一些行,但是我收到错误消息:“所选文件是一个解决方案文件,但似乎已损坏,无法打开”。
根据这篇博客的说法,评论是通过“#”完成的,但是当我尝试注释掉GlobalSection(有关Team Foundation Server源代码控制绑定的部分)中的每一行时,会出现上述错误。是否有其他方法可以注释掉sln文件中的行?
编辑-我想要注释掉的部分:
GlobalSection(TeamFoundationVersionControl) = preSolution
        SccNumberOfProjects = 2
        SccEnterpriseProvider = {4BA58AB2-18FA-4D8F-95F4-32FFDF27D184C}
        SccTeamFoundationServer = http://oxy:8080/tfs/projects
        SccLocalPath0 = .
        SccProjectUniqueName1 = Accounts\\Accounts.vbproj
        SccProjectName1 = Accounts
        SccLocalPath1 = Accounts
EndGlobalSection

我试过这个方法,但没有生效:

#  GlobalSection(TeamFoundationVersionControl) = preSolution
#           SccNumberOfProjects = 2
#           SccEnterpriseProvider = {4BA58AB2-18FA-4D8F-95F4-32FFDF27D184C}
#           SccTeamFoundationServer = http://oxy:8080/tfs/projects
#           SccLocalPath0 = .
#           SccProjectUniqueName1 = Accounts\\Accounts.vbproj
#           SccProjectName1 = Accounts
#           SccLocalPath1 = Accounts
#    EndGlobalSection

附注:我试过使用"#"来进行单行注释 - 这种方式可以实现。同时,删除整个部分也是可行的。但我不想删除它,只是想对其进行注释。


1
嗨,请展示一下你的代码。也许你的注释是正确的,但你可能注释掉了一些重要的东西。 - baruchiro
1
@Baruch,这里没有代码。这是一个简单的问题,我想知道如何注释.sln文件。不过,我会在编辑后的问题中加入一些内容,看起来又要因为无缘无故的原因被踩了... - Lucy82
1个回答

7

我认为在.sln文件中没有官方定义的注释。这取决于解析器。

原则上,.sln文件是一个基于关键字(ProjectSectionEndGlobalSection)和行尾字符的声明性文件。我没有看到统一的格式描述。

MSBuild

所以我们不知道Visual Studio如何读取.sln文件,但你可以在msbuild code中看到,任何不以const words之一开头的行都不会进入对象:

while ((str = ReadLine()) != null)
{
    if (str.StartsWith("Project(", StringComparison.Ordinal))
    {
        ParseProject(str);
    }
    else if (str.StartsWith("GlobalSection(NestedProjects)", StringComparison.Ordinal))
    {
        ParseNestedProjects();
    }
    else if (str.StartsWith("GlobalSection(SolutionConfigurationPlatforms)", StringComparison.Ordinal))
    {
        ParseSolutionConfigurations();
    }
    else if (str.StartsWith("GlobalSection(ProjectConfigurationPlatforms)", StringComparison.Ordinal))
    {
        rawProjectConfigurationsEntries = ParseProjectConfigurations();
    }
    else if (str.StartsWith("VisualStudioVersion", StringComparison.Ordinal))
    {
        _currentVisualStudioVersion = ParseVisualStudioVersion(str);
    }
    else
    {
        // No other section types to process at this point, so just ignore the line
        // and continue.
    }
}

Visual Studio

根据这篇博客,注释是用“#”来完成的。

那不准确。你可以在任何地方添加任意文本,而不需要使用#,文件仍然正确。

所以,在Visual Studio中,你目前不知道官方格式,但你需要“打破”当前格式。

你可以尝试更改关键字,比如在它们的开头添加一个字母。 根据我的尝试,特殊字符(如#%)不会破坏你的关键字。


感谢回复。看起来我不能做我所希望的事情 :( - Lucy82
1
@Lucy82 我同意...现在。我在文档中打开了一个问题(https://github.com/MicrosoftDocs/visualstudio-docs/issues/2766),希望这个主题能够被提出来。 - baruchiro
再次感谢。我希望那个问题有一天会得到解答。 - Lucy82

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接