Exemple #1
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);
            }
        }