5

我正在尝试临时注释 .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

PS:我尝试了使用“ # ”的单行注释- 有效。并且删除整个部分也可以。但我不想删除它,只是评论它。

4

1 回答 1

5

我认为.sln文件中没有正式的评论定义。这取决于解析器

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

微软构建

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

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中,您目前不知道官方格式,但您需要“打破”当前格式。

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

于 2019-02-25T10:33:41.927 回答