Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8614607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:09:36+00:00 2026-06-12T05:09:36+00:00

I am working on a code generator project that creates solution with customizable layers.

  • 0

I am working on a code generator project that creates solution with customizable layers.
for now I am able to create the .sln file by writing all the elements in code. but the project files don’t need this, they can be edited using MSBuild Project class.

I want to add a Website project template support and etc, so this way I edit the .sln file is not cool, I wanted to know that is there a better way to do this, like MSBuild or something else ?

I saw Programmatically generate Visual Studio Solution that says to use Visual Studio SDK (which is for extending visual studio, writing plugins …), but there isn’t any code sample.

thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:09:38+00:00Added an answer on June 12, 2026 at 5:09 am

    Here is how to use SLNTools to create sln file in code. The code is a mess! But it works!

    SLN Tools project is able to create sln file from project files. It’s open source and it provides UI for editing and merging sln files. In this case you can use the core project and by referencing the ‘CWDev.SLNTools.Core.dll’ in your project you can write a messy(!) code like this:

    NOTE: Some parts of class are not shown here and also There’s some custom objects of my own project like Sln, Project and … that should not be mistaken with SLNTools Objects with same name. I commented whereever needed!

    using CWDev.SLNTools.Core;
    using SlnFile = CWDev.SLNTools.Core.SolutionFile;
    using SlnProject = CWDev.SLNTools.Core.Project;
    using SeptaCodeGenerator.Core.IO;
    
    public class SlnFileManager
    {
        // * Note: Sln is of my own type.
        Sln _sln;
        // * SolutionFile is the type in SLNTools project that we use
        SlnFile _slnFile;
    
        public void WriteNewSlnFile(Sln slnObject)
        {
            _sln = slnObject;
            _slnFile = new SlnFile(); // or you can read sln file like below
            using (SolutionFileReader reader = new SolutionFileReader(_sln.ObjectFullPath))
                _slnFile = reader.ReadSolutionFile();
            AddHeaders();
            AddGlobalSections();
            // add projects
            List<SolutionNode> sns = _sln.GetAllSubItemsOf(typeof(SolutionFolder), typeof(ProjectNode));
            foreach (SolutionNode sn in sns)
                _slnFile.Projects.Add(CreateProject(sn));
    
            using (SolutionFileWriter writer = new SolutionFileWriter(_sln.ObjectFullPath))
                writer.WriteSolutionFile(_slnFile);
        }
    
        // this is how I create and add project sections, using Section and PropertyLine
        private SlnProject CreateProject(SolutionNode sn)
        {
            List<Section> projectSections = CreateProjectSections(sn);
            List<PropertyLine> versionControlLines = CreateVersionControlLines(sn);
            List<PropertyLine> projectConfigurationPlatformsLines = CreateProjectConfigurationPlatformsLines(sn);
    
            string parentGuid = (sn.Parent is Sln ? null : sn.Parent.InstanceGuidSt);
            string relativePath = (sn is Project) ? (sn as Project).ProjFile.ObjectRelativePath : sn.ObjectRelativePath;
            return new CWDev.SLNTools.Core.Project(_slnFile, sn.InstanceGuidSt, sn.TypeGuidSt, sn.Name, relativePath, parentGuid,
                projectSections, versionControlLines, projectConfigurationPlatformsLines);
        }
    
        // this method creates ProjectSections(WebsiteProperties)
        private List<Section> CreateProjectSections(SolutionNode project)
        {
            Section sec = null;
            var lines = new List<PropertyLine>();
            if (project is SolutionFolder)
            {
                List<SolutionNode> files = project.GetAllSubItemsOf(typeof(SolutionFile));
                foreach (SolutionNode item in files)
                {
                    // * consideration required
                    lines.Add(new PropertyLine(item.ObjectRelativePath, item.ObjectRelativePath));
                }
                if (lines.Count > 0)
                    sec = new Section("SolutionItems", "ProjectSection", "preProject", lines);
            }
            // *** here is the code that I wrote to add website projects ***
            else if (project is WebSiteProject)
            {
                var website = project as WebSiteProject;
                if (_sln.IsUnderSourceControl)
                {
                        lines.AddRange(new PropertyLine[]
                        {
                            new PropertyLine("SccProjectName", "\"SAK\""),
                            new PropertyLine("SccAuxPath", "\"SAK\""),
                            new PropertyLine("SccLocalPath", "\"SAK\""),
                            new PropertyLine("SccProvider", "\"SAK\"")
                        });
    
                }
                if (_sln.SolutionVersion == SolutionFileVersion.V11VS2010)
                    lines.Add(new PropertyLine("TargetFrameworkMoniker", "\".NETFramework,Version%3Dv4.0\""));
                else
                    lines.Add(new PropertyLine("TargetFramework", "\"3.5\""));
                // add project references
                string projectReferences = "";
                foreach (Project proj in website.ReferencedProjects)
                    projectReferences += proj.InstanceGuidSt + "|" + proj.ClassName + ".dll;";
                lines.Add(new PropertyLine("ProjectReferences", "\"" + projectReferences + "\""));
    
                string debugConf = "Debug.AspNetCompiler.";
                string releaseConf = "Release.AspNetCompiler.";
                string str = debugConf;
                int k = 0;
                while (k < 2)
                {
                    // other properties
                    lines.AddRange(new PropertyLine[]
                    {
                        new PropertyLine(str + "VirtualPath", "\"/" + website.Name + "\""),
                        new PropertyLine(str + "PhysicalPath", "\"" + website.ObjectRelativePath + "\\\""),
                        new PropertyLine(str + "TargetPath", ("\"PrecompiledWeb\\" + website.Name + "\\\"")),
                        new PropertyLine(str + "Updateable", "\"true\""),
                        new PropertyLine(str + "ForceOverwrite", "\"true\""),
                        new PropertyLine(str + "FixedNames", "\"false\""),
                        new PropertyLine(str + "Debug", (k == 0 ? "\"True\"" : "\"False\""))
                    });
    
                    if (k++ == 0)
                        str = releaseConf;
                }
                Random rand = new Random();
                lines.Add(new PropertyLine("VWDPort", "\"" + rand.Next(1111, 65000).ToString() + "\""));
                lines.Add(new PropertyLine("DefaultWebSiteLanguage",
                    website.Language == SeptaCodeGenerator.Core.Language.CodeLanguage.CSharp ? "\"Visual C#\"" : "\"Visual Basic\""));
    
                sec = new Section("WebsiteProperties", "ProjectSection", "preProject", lines);
            }
            var sections = new List<Section>();
            if (sec != null)
                sections.Add(sec);
            return sections;
        }
    }
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this working code, but now i need to be able to change
Im trying to create a RSS feed reader for a project that I working
I am working on an Android project in that i need to send the
I'm working on updating a project which uses the following code to place a
I'm running into an issue while unit-testing a Python project that I'm working on
I was working on a project and, while playing around with the code, I
I'm working on a visual studio 2008 add-in that will generate data-access code by
I am currently working on a project that will involve credit card swipes for
I am working as a part of a large project. The company that I
I am working on code snippet where I want to create an RED5 rtmp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.