private string WriteCodeToNewFileInProject(Project project, string code, string idealBaseFilename) { string newFilepath = _projectServices.GetUniqueFilepathForNewFileInProject(project, idealBaseFilename); File.WriteAllText(newFilepath, code); CodeRush.Solution.AddFileToProject(project.Name, newFilepath); return(newFilepath); }
public void Apply(ApplyContentEventArgs ea, string selectedProjectName) { Project selectedProject = _projectServices.GetProject(selectedProjectName); string filename = _projectServices.GetUniqueFilepathForNewFileInProject(selectedProject, ea.Element.Name); //selectedProject.CodeModel.DTE.ItemOperations.AddNewItem(@"Visual C# Items\Code\Class", filename); var currentProject = DevExpress.CodeRush.Core.SolutionHelper.GetProjectByName(CodeRush.Project.Active.Name); var projectToAddAsReference = DevExpress.CodeRush.Core.SolutionHelper.GetProjectByName(selectedProjectName); currentProject.CodeModel.DTE.ItemOperations.AddNewItem(@"Visual C# Items\Code\Class", filename); var vsProj = currentProject.Object as VSLangProj.VSProject; if (vsProj != null) { vsProj.References.AddProject(projectToAddAsReference); } }