Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comment lines in .sln file

Tags:

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.

like image 609
Lucy82 Avatar asked Feb 22 '19 16:02

Lucy82


People also ask

How do I edit .sln files?

Right-click the solution file (. SLN), then select “Edit with Notepad“. 6. Now save your changes and close Notepad.

What does sln file contain?

sln file. The . sln file contains text-based information the environment uses to find and load the name-value parameters for the persisted data and the project VSPackages it references. When a user opens a solution, the environment cycles through the preSolution , Project , and postSolution information in the .

Should you check in .sln files?

Yes, you always want to include the . sln file, it includes the links to all the projects that are in the solution. Save this answer.

How do I read .sln files?

A file with . SLN extension represents a Visual Studio solution file that keeps information about the organization of projects in a solution file. The contents of such a solution file are written in plain text inside the file and can be observed/edited by opening the file in any text editor.


1 Answers

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.

like image 77
baruchiro Avatar answered Jan 01 '23 08:01

baruchiro