sln-file

Comment lines in .sln file


I'm trying to comment some lines in .sln file temporarly, but I receive error: "The selected file is a solution file, but appears to be corrupted and cannot be opened"

According to this blog comments are done by "#", but when I comment out every line in GlobalSection (section about Team Foundation Server source control binding) I get above error. Is there any other way to comment out lines in .sln ?

EDIT - section of which I want to comment out:

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

I tried this, but not working:

#  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

P.S.: I tried a single line comment using "#" - that works. And removing whole section also works. But I don't want to delete It, just comment It.


Solution

  • I don't think there is an official definition of comments in the .sln file. It depends on the parser.

    In principle, a .sln file is a declarative file, based on the keywords (ProjectSection, EndGlobalSection) and the end-line char. I don't see a uniform format description.

    MSBuild

    So we don't know how Visual Studio reads the .sln file, but you can see in the msbuild code that any line that doesn't start with one of the const words will not enter to the object:

    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

    According to this blog comments are done by "#"

    That is not accurate. You can add lines with any text where you want, without the #, and the file will stay correct.

    So, in Visual Studio, you currently don't know the official format, but you need to "break" the current format.

    You can try changing the keywords, such as adding a letter to them at the beginning. From what I've tried, special characters (such as #, %) don't break your keywords.