Пример #1
0
        public static void ExecuteNewProjectCommand()
        {
            var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Korduene", "Projects");

            if (Current.Instance.Workspace == null)
            {
                var newProject = Current.Instance.UIServices.CreateDialog <NewProjectData>(DialogType.NewProject, dir);

                if (newProject.Success)
                {
                    Current.Instance.CreateSolution(newProject.Data.Template.ChosenName, newProject.Data.Directory, newProject.Data.Template);
                }

                return;
            }

            dir = Path.GetDirectoryName(Current.Instance.Workspace.SlnFile.FullPath);

            var result = Current.Instance.UIServices.CreateDialog <NewProjectData>(DialogType.NewProject, dir);

            if (!result.Success)
            {
                return;
            }

            var template = result.Data.Template;
            var name     = result.Data.Template.ChosenName;

            //create proj dir
            var projDir = Path.Combine(result.Data.Directory, name);

            template.CreateFiles(projDir);

            var fullPath = Path.Combine(result.Data.Directory, name, result.Data.Template.ChosenName + Path.GetExtension(result.Data.Template.MainFile));

            var proj = new Microsoft.DotNet.Cli.Sln.Internal.SlnProject()
            {
                Id       = template.Id,
                FilePath = Path.GetRelativePath(dir, fullPath),
                Name     = name,
                TypeGuid = template.ProjectTypeGuid
            };

            Current.Instance.Workspace.SlnFile.Projects.Add(proj);
            Current.Instance.Workspace.SlnFile.Write();
            Current.Instance.OpenSolution(Current.Instance.Workspace.SlnFile.FullPath);
        }
Пример #2
0
        public void CreateSolution(string name, string directory, ProjectTemplate template)
        {
            var slnDir = Path.Combine(directory, name);

            Directory.CreateDirectory(slnDir);

            var sln = new Microsoft.DotNet.Cli.Sln.Internal.SlnFile
            {
                FullPath                   = Path.Combine(slnDir, $"{name}.sln"),
                ProductDescription         = "Visual Studio Version 16",
                FormatVersion              = "12.00",
                VisualStudioVersion        = "16",
                MinimumVisualStudioVersion = "10"
            };

            //create project dir
            var projDir = Path.Combine(slnDir, name);

            template.CreateFiles(projDir);

            var fullPath = Path.Combine(directory, name, template.ChosenName + Path.GetExtension(template.MainFile));

            var proj = new Microsoft.DotNet.Cli.Sln.Internal.SlnProject()
            {
                Id       = template.Id,
                FilePath = Path.GetRelativePath(directory, fullPath),
                Name     = name,
                TypeGuid = template.ProjectTypeGuid
            };

            sln.Projects.Add(proj);

            var projConfig = new Microsoft.DotNet.Cli.Sln.Internal.SlnPropertySet(proj.Id);

            projConfig.SetValue("Debug|Any CPU.ActiveCfg", "Debug|Any CPU");
            projConfig.SetValue("Debug|Any CPU.Build.0", "Debug|Any CPU");
            projConfig.SetValue("Release|Any CPU.ActiveCfg", "Release|Any CPU");
            projConfig.SetValue("Release|Any CPU.Build.0", "Release|Any CPU");

            sln.SolutionConfigurationsSection.SetValue("Debug|Any CPU", "Debug|Any CPU");
            sln.SolutionConfigurationsSection.SetValue("Release|Any CPU", "Release|Any CPU");

            sln.ProjectConfigurationsSection.Add(projConfig);
            var slnProperties = new Microsoft.DotNet.Cli.Sln.Internal.SlnSection()
            {
                Id = "SolutionProperties"
            };

            slnProperties.Properties.SetValue("HideSolutionNode", "FALSE");
            sln.Sections.Add(slnProperties);

            var extGlobals = new Microsoft.DotNet.Cli.Sln.Internal.SlnSection()
            {
                Id          = "ExtensibilityGlobals",
                SectionType = Microsoft.DotNet.Cli.Sln.Internal.SlnSectionType.PostProcess
            };

            extGlobals.Properties.SetValue("SolutionGuid", $"{{{Guid.NewGuid().ToString()}}}");
            sln.Sections.Add(extGlobals);

            sln.Write();

            OpenSolution(sln.FullPath);
        }