Get all projects in an open solution in Rider

Answered

I am building a plugin for .net solutions in Rider.

 

In Jetbrains Rider, a given .net Solution can have multiple projects inside it. I want to get all the projects available in the currently opened solution. How will I be able to get the available projects?

 

The use of

ProjectManager.getInstance().openProjects

will always result in the giving an array with only the open solution.

3 comments
Comment actions Permalink
Official comment

This is where terminology causes issues :) A "project" in the frontend IntelliJ part of a plugin refers to the IntelliJ concept of a project, which is more similar to a .net solution. You can take a look at 

WorkspaceModel.getInstance(project).findProjects()

and various other WorkspaceModel methods and extension functions. This will return the workspace model entity, and more details can be retrieved from the associated descriptor (which might need down casting).

Comment actions Permalink

I have a solution here where I read the solution to get the projects as such

fun getProjectsInSolution(project: Project): List<String> {
return try {
val solutionDirectoryVirtualFile = LocalFileSystem.getInstance().findFileByPath(project.basePath!!)!!
val solutionVirtualFile = solutionDirectoryVirtualFile.children.first { it.name.contains(".sln") }
val solutionContent = LoadTextUtil.loadText(solutionVirtualFile).toString()
val projectsDetail = StringUtils.substringsBetween(solutionContent, "Project", "EndProject")
projectsDetail.map {
StringUtils.substringBetween(it, "= \"", "\"")
}
} catch (ex: Exception) {
arrayListOf(project.name)
}
}

If there is any other way to getting the info I need please let me know. I'll just leave this code here in case someone needs it.

1
Comment actions Permalink

Matt Ellis

Would

WorkspaceModel.getInstance(project).findProjects()

give me what the IDE considers projects identified inside the loaded project (solution)?

0

Please sign in to leave a comment.