Пример #1
0
		public static void AddProject(ISolutionFolderNode solutionFolderNode, string fileName)
		{
			if (solutionFolderNode == null)
				throw new ArgumentNullException("solutionFolderNode");
			ProjectLoadInformation loadInfo = new ProjectLoadInformation(solutionFolderNode.Solution, fileName, Path.GetFileNameWithoutExtension(fileName));
			AddProject(solutionFolderNode, ProjectBindingService.LoadProject(loadInfo));
		}
        public static IProject LoadProject(ProjectLoadInformation loadInformation)
        {
            if (loadInformation == null)
            {
                throw new ArgumentNullException("loadInformation");
            }

            string           location        = FileUtility.NormalizePath(loadInformation.FileName);
            string           title           = loadInformation.ProjectName;
            IProgressMonitor progressMonitor = loadInformation.ProgressMonitor;

            progressMonitor.CancellationToken.ThrowIfCancellationRequested();

            IProjectBinding binding = ProjectBindingService.GetBindingPerProjectFile(location);
            IProject        newProject;

            if (!(binding != null && binding.HandlingMissingProject) && !File.Exists(location))
            {
                newProject          = new MissingProject(location, title);
                newProject.TypeGuid = loadInformation.TypeGuid;
            }
            else
            {
                if (binding != null)
                {
                    try {
                        newProject = binding.LoadProject(loadInformation);
                    } catch (ProjectLoadException ex) {
                        LoggingService.Warn("Project load error", ex);
                        progressMonitor.ShowingDialog = true;
                        newProject                    = new UnknownProject(location, title, ex.Message, true);
                        newProject.TypeGuid           = loadInformation.TypeGuid;
                        progressMonitor.ShowingDialog = false;
                    } catch (UnauthorizedAccessException ex) {
                        LoggingService.Warn("Project load error", ex);
                        progressMonitor.ShowingDialog = true;
                        newProject                    = new UnknownProject(location, title, ex.Message, true);
                        newProject.TypeGuid           = loadInformation.TypeGuid;
                        progressMonitor.ShowingDialog = false;
                    }
                }
                else
                {
                    string ext = Path.GetExtension(location);
                    if (".proj".Equals(ext, StringComparison.OrdinalIgnoreCase) ||
                        ".build".Equals(ext, StringComparison.OrdinalIgnoreCase))
                    {
                        newProject          = new MSBuildFileProject(location, title);
                        newProject.TypeGuid = loadInformation.TypeGuid;
                    }
                    else
                    {
                        newProject          = new UnknownProject(location, title);
                        newProject.TypeGuid = loadInformation.TypeGuid;
                    }
                }
            }
            return(newProject);
        }
 public CSharpProject(ProjectLoadInformation loadInformation)
     : base(loadInformation)
 {
     Init();
     if (loadInformation.InitializeTypeSystem)
     {
         InitializeProjectContent(new CSharpProjectContent());
     }
 }
Пример #4
0
 public AlProject(ProjectLoadInformation loadInformation)
     : base(loadInformation)
 {
     info = loadInformation;
     Init();
     if (loadInformation.InitializeTypeSystem)
     {
         InitializeProjectContent(new AlProjectContent());
     }
 }
Пример #5
0
        public static void AddProject(ISolutionFolderNode solutionFolderNode, string fileName)
        {
            if (solutionFolderNode == null)
            {
                throw new ArgumentNullException("solutionFolderNode");
            }
            ProjectLoadInformation loadInfo = new ProjectLoadInformation(solutionFolderNode.Solution, fileName, Path.GetFileNameWithoutExtension(fileName));

            AddProject(solutionFolderNode, ProjectBindingService.LoadProject(loadInfo));
        }
        public void NotMSBuildBasedProject()
        {
            ProjectLoadInformation info = new ProjectLoadInformation(MockSolution.Create(), FileName.Create(@"C:\Projects\Test.proj"), "Test");

            MissingProject          project     = new MissingProject(info);
            ITestProject            testProject = new NUnitTestProject(project);
            NUnitConsoleApplication app         = new NUnitConsoleApplication(new[] { testProject });

            Assert.AreEqual(project.GetType().BaseType, typeof(AbstractProject), "MissingProject should be derived from AbstractProject.");
            Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console.exe", app.FileName);
        }
Пример #7
0
        public VbpProject(ProjectLoadInformation info)
            : base(info)
        {
            _projectReader = new Vb6ProjectReader();
            _projectWriter = new Vb6ProjectWriter();

            FileInfo file = new FileInfo(info.FileName);

            using (Stream stream = file.OpenRead())
            {
                _vbProject = _projectReader.Read(file, stream);
            }

            AddGenericItems();
            AddReferences();

            _symbolCache = VbpProjectSymbolCache.FromProject(this);
        }
Пример #8
0
        /// <summary>
        /// Create a new C++ project that loads the specified .vcproj file.
        /// </summary>
        public CppProject(ProjectLoadInformation info)
            : base(info)
        {
            this.Name     = info.ProjectName;
            this.FileName = info.FileName;

            using (StreamReader r = new StreamReader(info.FileName, Encoding.Default)) {
                try {
                    document.Load(r);
                } catch (Exception ex) {
                    throw new ProjectLoadException(ex.Message, ex);
                }
            }
            if (document.DocumentElement.Name != "VisualStudioProject")
            {
                throw new ProjectLoadException("The project is not a visual studio project.");
            }
            XmlElement filesElement = document.DocumentElement["Files"];

            if (filesElement != null)
            {
                foreach (XmlElement filterElement in filesElement.ChildNodes.OfType <XmlElement>())
                {
                    if (filterElement.Name == "Filter")
                    {
                        FileGroup group = new FileGroup(this, filterElement);
                        groups.Add(group);
                        foreach (XmlElement fileElement in filterElement.ChildNodes.OfType <XmlElement>())
                        {
                            if (fileElement.Name == "File" && fileElement.HasAttribute("RelativePath"))
                            {
                                items.Add(new FileItem(group, fileElement));
                            }
                        }
                    }
                }
            }

            this.projectItems = new CppProjectItemsCollection(this);
        }
Пример #9
0
 public IProject LoadProject(ProjectLoadInformation info)
 {
     return(new CppProject(info));
 }
Пример #10
0
 public CSharpProject(ProjectLoadInformation loadInformation)
     : base(loadInformation)
 {
     Init();
 }
Пример #11
0
 IProject IProjectBinding.LoadProject(ProjectLoadInformation info)
 {
     return(new VbpProject(info));
 }
Пример #12
0
 public CppProject(ProjectLoadInformation info)
     : base(info)
 {
 }
Пример #13
0
 public AimProject(ProjectLoadInformation info) : base(info)
 {
     // Inicializa a classe
     Init();
 }
Пример #14
0
 public PythonProject(ProjectLoadInformation info)
     : base(info)
 {
 }
Пример #15
0
 public IProject LoadProject(ProjectLoadInformation loadInformation)
 {
     return(new SnippetCompilerProject(loadInformation));
 }
Пример #16
0
 public FSharpProject(ProjectLoadInformation info) : base(info)
 {
 }
 public SnippetCompilerProject(ProjectLoadInformation loadInformation)
     : base(loadInformation)
 {
 }
Пример #18
0
 public RubyProject(ProjectLoadInformation info)
     : base(info)
 {
 }
Пример #19
0
 public BooProject(ProjectLoadInformation info)
     : base(info)
 {
     Init();
 }
Пример #20
0
        //Show prompt, create files from template, create project, execute command, save project
        public bool CreateProject(ProjectTemplateResult templateResults, string defaultLanguage, ISolutionFolder target)
        {
            var      projectCreateOptions = templateResults.Options;
            var      parentSolution       = templateResults.Options.Solution;
            IProject project = null;
            bool     success = false;

            try
            {
                string language = string.IsNullOrEmpty(languageName) ? defaultLanguage : languageName;
                ProjectBindingDescriptor descriptor   = SD.ProjectService.ProjectBindings.FirstOrDefault(b => b.Language == language);
                IProjectBinding          languageinfo = (descriptor != null) ? descriptor.Binding : null;

                if (languageinfo == null)
                {
                    MessageService.ShowError(
                        StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.CantCreateProjectWithTypeError}",
                                           new StringTagPair("type", language)));
                    return(false);
                }

                DirectoryName projectBasePath = GetProjectBasePath(projectCreateOptions);
                string        newProjectName  = StringParser.Parse(name, new StringTagPair("ProjectName", projectCreateOptions.ProjectName));
                Directory.CreateDirectory(projectBasePath);
                FileName projectLocation      = projectBasePath.CombineFile(newProjectName + descriptor.ProjectFileExtension);
                ProjectCreateInformation info = new ProjectCreateInformation(parentSolution, projectLocation);
                info.TargetFramework = projectCreateOptions.TargetFramework;

                StringBuilder standardNamespace = new StringBuilder();
                // filter 'illegal' chars from standard namespace
                if (!string.IsNullOrEmpty(newProjectName))
                {
                    char ch = '.';
                    for (int i = 0; i < newProjectName.Length; ++i)
                    {
                        if (ch == '.')
                        {
                            // at beginning or after '.', only a letter or '_' is allowed
                            ch = newProjectName[i];
                            if (!Char.IsLetter(ch))
                            {
                                standardNamespace.Append('_');
                            }
                            else
                            {
                                standardNamespace.Append(ch);
                            }
                        }
                        else
                        {
                            ch = newProjectName[i];
                            // can only contain letters, digits or '_'
                            if (!Char.IsLetterOrDigit(ch) && ch != '.')
                            {
                                standardNamespace.Append('_');
                            }
                            else
                            {
                                standardNamespace.Append(ch);
                            }
                        }
                    }
                }

                info.TypeGuid      = descriptor.TypeGuid;
                info.RootNamespace = standardNamespace.ToString();
                info.ProjectName   = newProjectName;
                if (!string.IsNullOrEmpty(defaultPlatform))
                {
                    info.ActiveProjectConfiguration = new ConfigurationAndPlatform("Debug", defaultPlatform);
                }

                RunPreCreateActions(info);

                StringParserPropertyContainer.FileCreation["StandardNamespace"] = info.RootNamespace;

                if (File.Exists(projectLocation))
                {
                    if (!MessageService.AskQuestion(
                            StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteProjectQuestion}",
                                               new StringTagPair("projectLocation", projectLocation)),
                            "${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion.InfoName}"))
                    {
                        return(false);                        //The user doesnt want to overwrite the project...
                    }
                }

                //Show prompt if any of the files exist
                StringBuilder existingFileNames = new StringBuilder();
                foreach (FileDescriptionTemplate file in files)
                {
                    string fileName = Path.Combine(projectBasePath, StringParser.Parse(file.Name, new StringTagPair("ProjectName", info.ProjectName)));

                    if (File.Exists(fileName))
                    {
                        if (existingFileNames.Length > 0)
                        {
                            existingFileNames.Append(", ");
                        }
                        existingFileNames.Append(Path.GetFileName(fileName));
                    }
                }

                bool overwriteFiles = true;
                if (existingFileNames.Length > 0)
                {
                    if (!MessageService.AskQuestion(
                            StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion}",
                                               new StringTagPair("fileNames", existingFileNames.ToString())),
                            "${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion.InfoName}"))
                    {
                        overwriteFiles = false;
                    }
                }



                #region Copy files to target directory
                foreach (FileDescriptionTemplate file in files)
                {
                    string fileName = Path.Combine(projectBasePath, StringParser.Parse(file.Name, new StringTagPair("ProjectName", info.ProjectName)));
                    if (File.Exists(fileName) && !overwriteFiles)
                    {
                        continue;
                    }

                    try
                    {
                        if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                        }
                        if (!String.IsNullOrEmpty(file.BinaryFileName))
                        {
                            // Binary content
                            File.Copy(file.BinaryFileName, fileName, true);
                        }
                        else
                        {
                            // Textual content
                            StreamWriter sr          = new StreamWriter(File.Create(fileName), SD.FileService.DefaultFileEncoding);
                            string       fileContent = StringParser.Parse(file.Content,
                                                                          new StringTagPair("ProjectName", projectCreateOptions.ProjectName),
                                                                          new StringTagPair("SolutionName", projectCreateOptions.SolutionName),
                                                                          new StringTagPair("FileName", fileName));
                            fileContent = StringParser.Parse(fileContent);
                            if (SD.EditorControlService.GlobalOptions.IndentationString != "\t")
                            {
                                fileContent = fileContent.Replace("\t", SD.EditorControlService.GlobalOptions.IndentationString);
                            }
                            sr.Write(fileContent);
                            sr.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageService.ShowException(ex, "Exception writing " + fileName);
                    }
                }
                #endregion

                #region Create Project
                try {
                    info.InitializeTypeSystem = false;
                    project = languageinfo.CreateProject(info);
                } catch (ProjectLoadException ex) {
                    MessageService.ShowError(ex.Message);
                    return(false);
                }
                #endregion

                #region Create Project Items, Imports and Files
                // Add Project items
                if (!project.Items.IsReadOnly)
                {
                    foreach (ProjectItem projectItem in projectItems)
                    {
                        ProjectItem newProjectItem = new UnknownProjectItem(
                            project,
                            StringParser.Parse(projectItem.ItemType.ItemName),
                            StringParser.Parse(projectItem.Include,
                                               new StringTagPair("ProjectName", projectCreateOptions.ProjectName),
                                               new StringTagPair("SolutionName", projectCreateOptions.SolutionName))
                            );
                        foreach (string metadataName in projectItem.MetadataNames)
                        {
                            string metadataValue = projectItem.GetMetadata(metadataName);
                            // if the input contains any special MSBuild sequences, don't escape the value
                            // we want to escape only when the special characters are introduced by the StringParser.Parse replacement
                            if (metadataValue.Contains("$(") || metadataValue.Contains("%"))
                            {
                                newProjectItem.SetMetadata(StringParser.Parse(metadataName), StringParser.Parse(metadataValue));
                            }
                            else
                            {
                                newProjectItem.SetEvaluatedMetadata(StringParser.Parse(metadataName), StringParser.Parse(metadataValue));
                            }
                        }
                        project.Items.Add(newProjectItem);
                    }
                }

                // Add properties from <PropertyGroup>
                // This must be done before adding <Imports>, because the import path can refer to properties.
                if (projectProperties.Count > 0)
                {
                    if (!(project is MSBuildBasedProject))
                    {
                        throw new Exception("<PropertyGroup> may be only used in project templates for MSBuildBasedProjects");
                    }

                    foreach (ProjectProperty p in projectProperties)
                    {
                        ((MSBuildBasedProject)project).SetProperty(
                            StringParser.Parse(p.Configuration),
                            StringParser.Parse(p.Platform),
                            StringParser.Parse(p.Name),
                            StringParser.Parse(p.Value),
                            p.Location,
                            p.ValueIsLiteral
                            );
                    }
                }

                // Add Imports
                if (clearExistingImports || projectImports.Count > 0)
                {
                    MSBuildBasedProject msbuildProject = project as MSBuildBasedProject;
                    if (msbuildProject == null)
                    {
                        throw new Exception("<Imports> may be only used in project templates for MSBuildBasedProjects");
                    }
                    try {
                        msbuildProject.PerformUpdateOnProjectFile(
                            delegate {
                            var projectFile = msbuildProject.MSBuildProjectFile;
                            if (clearExistingImports)
                            {
                                foreach (var import in projectFile.Imports.ToArray())
                                {
                                    projectFile.RemoveChild(import);
                                }
                            }
                            foreach (Import projectImport in projectImports)
                            {
                                projectFile.AddImport(projectImport.Key).Condition = projectImport.Value;
                            }
                        });
                    } catch (InvalidProjectFileException ex) {
                        string message;
                        if (string.IsNullOrEmpty(importsFailureMessage))
                        {
                            message = "Error creating project:\n" + ex.Message;
                        }
                        else
                        {
                            message = importsFailureMessage + "\n\n" + ex.Message;
                        }
                        throw new ProjectLoadException(message, ex);
                    }
                }

                // Add Files
                if (!project.Items.IsReadOnly)
                {
                    foreach (FileDescriptionTemplate file in files)
                    {
                        string          fileName    = Path.Combine(projectBasePath, StringParser.Parse(file.Name, new StringTagPair("ProjectName", projectCreateOptions.ProjectName)));
                        FileProjectItem projectFile = new FileProjectItem(project, project.GetDefaultItemType(fileName));

                        projectFile.Include = FileUtility.GetRelativePath(project.Directory, fileName);

                        file.SetProjectItemProperties(projectFile);

                        project.Items.Add(projectFile);
                    }
                }

                #endregion

                RunCreateActions(project);

                project.ProjectCreationComplete();

                // Save project
                project.Save();

                // HACK : close and reload
                var fn = project.FileName;
                project.Dispose();
                ProjectLoadInformation loadInfo = new ProjectLoadInformation(parentSolution, fn, fn.GetFileNameWithoutExtension());
                project = SD.ProjectService.LoadProject(loadInfo);
                target.Items.Add(project);
                project.ProjectLoaded();

                SD.GetRequiredService <IProjectServiceRaiseEvents>().RaiseProjectCreated(new ProjectEventArgs(project));
                templateResults.NewProjects.Add(project);
                success = true;
                return(true);
            } finally {
                if (project != null && !success)
                {
                    project.Dispose();
                }
            }
        }
Пример #21
0
 public ILAsmProject(ProjectLoadInformation info)
     : base(info)
 {
 }
Пример #22
0
 public IProject LoadProject(ProjectLoadInformation loadInformation)
 {
     return(new AlProject(loadInformation));
 }
Пример #23
0
 public VBNetProject(ProjectLoadInformation info)
     : base(info)
 {
     InitVB();
 }