Comment lines in .sln file
Asked Answered
R

1

10

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.

Reservoir answered 22/2, 2019 at 16:13 Comment(2)
Hi, please show us your code. Maybe the comment succeed but you comment out something important.Euphorbiaceous
@Baruch, there is no code. It's a simple question on how do I comment .sln file. However I will put something in edited question, looks like another downvote for no reason...Reservoir
E
7

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.

Euphorbiaceous answered 25/2, 2019 at 10:33 Comment(3)
thanks for response. Well looks like I can't do what I was hoping for :(Reservoir
@Reservoir I agree ... right now. I opened an issue in the documentation, hoping that the subject would come up.Euphorbiaceous
thanks again. I hope that question is going to be answered someday.Reservoir

© 2022 - 2024 — McMap. All rights reserved.