Example #1
0
        //TODO: find solution that contains the project if possible
        public async Task <Solution> GetWrapperSolution(ProgressMonitor monitor, string filename)
        {
            // First of all, check if a solution with the same name already exists

            string solFileName = Path.ChangeExtension(filename, ".sln");

            if (File.Exists(solFileName))
            {
                return((Solution)await Services.ProjectService.ReadWorkspaceItem(monitor, solFileName));
            }
            else
            {
                // Create a temporary solution and add the project to the solution
                SolutionItem sitem = await Services.ProjectService.ReadSolutionItem(monitor, filename);

                Solution tempSolution = new Solution();
                tempSolution.FileName = solFileName;
                tempSolution.ConvertToFormat(sitem.FileFormat);
                tempSolution.RootFolder.Items.Add(sitem);
                tempSolution.CreateDefaultConfigurations();
                await tempSolution.SaveAsync(monitor);

                return(tempSolution);
            }
        }
Example #2
0
        //TODO: find solution that contains the project if possible
        public Solution GetWrapperSolution(IProgressMonitor monitor, string filename)
        {
            // First of all, check if a solution with the same name already exists

            FileFormat[] formats = Services.ProjectService.FileFormats.GetFileFormats(filename, typeof(SolutionEntityItem));
            if (formats.Length == 0)
            {
                formats = new  [] { DefaultFileFormat }
            }
            ;

            Solution tempSolution = new Solution();

            FileFormat solutionFileFormat = formats.FirstOrDefault(f => f.CanWrite(tempSolution)) ?? DefaultFileFormat;

            string solFileName = solutionFileFormat.GetValidFileName(tempSolution, filename);

            if (File.Exists(solFileName))
            {
                return((Solution)Services.ProjectService.ReadWorkspaceItem(monitor, solFileName));
            }
            else
            {
                // Create a temporary solution and add the project to the solution
                tempSolution.SetLocation(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename));
                SolutionEntityItem sitem = Services.ProjectService.ReadSolutionItem(monitor, filename);
                tempSolution.ConvertToFormat(solutionFileFormat, false);
                tempSolution.RootFolder.Items.Add(sitem);
                tempSolution.CreateDefaultConfigurations();
                tempSolution.Save(monitor);
                return(tempSolution);
            }
        }