Example #1
0
 public static void AddProject(ISolutionFolderNode solutionFolderNode, string fileName)
 {
     if (solutionFolderNode == null)
     {
         throw new ArgumentNullException("solutionFolderNode");
     }
     AddProject(solutionFolderNode, LanguageBindingService.LoadProject(solutionFolderNode.Solution, fileName, Path.GetFileNameWithoutExtension(fileName)));
 }
        public static IProject ConvertOldProject(string fileName, Conversion conversion, IMSBuildEngineProvider provider)
        {
            string convertedFileName;

            if (conversion.IsVisualBasic)
            {
                convertedFileName = Path.ChangeExtension(fileName, ".vbproj");
            }
            else
            {
                convertedFileName = Path.ChangeExtension(fileName, ".csproj");
            }

            conversion.basePath = Path.GetDirectoryName(fileName);
            using (StreamReader fileReader = new StreamReader(fileName)) {
                RunConverter(fileReader, convertedFileName, "CSharp_prjx2csproj.xsl", conversion);
            }
            using (StreamReader fileReader = new StreamReader(fileName)) {
                RunConverter(fileReader, convertedFileName + ".user", "CSharp_prjx2csproj_user.xsl", conversion);
            }

            return(LanguageBindingService.LoadProject(provider, convertedFileName, Conversion.GetProjectName(fileName)));
        }
Example #3
0
        /// <summary>
        /// Load a single project as solution.
        /// </summary>
        public static void LoadProject(string fileName)
        {
            string solutionFile = Path.ChangeExtension(fileName, ".sln");

            if (File.Exists(solutionFile))
            {
                LoadSolution(solutionFile);

                if (openSolution != null)
                {
                    bool found = false;
                    foreach (IProject p in openSolution.Projects)
                    {
                        if (FileUtility.IsEqualFileName(fileName, p.FileName))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found == false)
                    {
                        string[,] parseArgs = { { "SolutionName", Path.GetFileName(solutionFile) }, { "ProjectName", Path.GetFileName(fileName) } };
                        int res = MessageService.ShowCustomDialog(MessageService.ProductName,
                                                                  StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.OpenCombine.SolutionDoesNotContainProject}", parseArgs),
                                                                  0, 2,
                                                                  StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.OpenCombine.SolutionDoesNotContainProject.AddProjectToSolution}", parseArgs),
                                                                  StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.OpenCombine.SolutionDoesNotContainProject.CreateNewSolution}", parseArgs),
                                                                  "${res:Global.IgnoreButtonText}");
                        if (res == 0)
                        {
                            // Add project to solution
                            Commands.AddExitingProjectToSolution.AddProject((ISolutionFolderNode)ProjectBrowserPad.Instance.SolutionNode, fileName);
                            SaveSolution();
                            return;
                        }
                        else if (res == 1)
                        {
                            CloseSolution();
                            try {
                                File.Copy(solutionFile, Path.ChangeExtension(solutionFile, ".old.sln"), true);
                            } catch (IOException) {}
                        }
                        else
                        {
                            // ignore, just open the solution
                            return;
                        }
                    }
                    else
                    {
                        // opened solution instead and correctly found the project
                        return;
                    }
                }
                else
                {
                    // some problem during opening, abort
                    return;
                }
            }
            Solution solution = new Solution();

            solution.Name = Path.GetFileNameWithoutExtension(fileName);
            ILanguageBinding binding = LanguageBindingService.GetBindingPerProjectFile(fileName);
            IProject         project;

            if (binding != null)
            {
                project = LanguageBindingService.LoadProject(solution, fileName, solution.Name);
                if (project is UnknownProject)
                {
                    if (((UnknownProject)project).WarningDisplayedToUser == false)
                    {
                        ((UnknownProject)project).ShowWarningMessageBox();
                    }
                    return;
                }
            }
            else
            {
                MessageService.ShowError(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.OpenCombine.InvalidProjectOrCombine}", new string[, ] {
                    { "FileName", fileName }
                }));
                return;
            }
            solution.AddFolder(project);
            ProjectSection configSection = solution.GetSolutionConfigurationsSection();

            foreach (string configuration in project.ConfigurationNames)
            {
                foreach (string platform in project.PlatformNames)
                {
                    string key;
                    if (platform == "AnyCPU")                       // Fix for SD2-786
                    {
                        key = configuration + "|Any CPU";
                    }
                    else
                    {
                        key = configuration + "|" + platform;
                    }
                    configSection.Items.Add(new SolutionItem(key, key));
                }
            }
            solution.FixSolutionConfiguration(new IProject[] { project });

            if (FileUtility.ObservedSave((NamedFileOperationDelegate)solution.Save, solutionFile) == FileOperationResult.OK)
            {
                // only load when saved succesfully
                LoadSolution(solutionFile);
            }
        }
 public static void AddProject(ISolutionFolderNode solutionFolderNode, string fileName)
 {
     AddProject(solutionFolderNode, LanguageBindingService.LoadProject(solutionFolderNode.Solution, fileName, Path.GetFileNameWithoutExtension(fileName)));
 }