Can't access app.config from IProject.Documents
-
Mittwoch, 11. April 2012 21:35
I am currently using the following code to parse through a sln file, but it does not include any files other than *.vb and *.cs in the project.Documents list. The project I am currently working on has need of being able to parse ALL file types that are referenced, not just code files.
var workspace = Workspace.LoadSolution(slnFile); var sln = workspace.CurrentSolution; foreach (var project in sln.Projects) { _logger.InfoFormat("Loading project '{0}' Language '{1}'", project.DisplayName, project.LanguageServices.Language); foreach (var option in project.ParseOptions.GetOptionNames()) { _logger.InfoFormat("Option: {0}={1}", option, project.ParseOptions.GetOption(option)); } _logger.InfoFormat(""); foreach (var document in project.Documents) { var path = document.DisplayName; if(document.Folders.Count > 0) path = string.Format(@"{0}\{1}", document.Folders.Aggregate((x, y) => string.Format(@"{0}\{1}", x, y)), document.DisplayName); _logger.InfoFormat(@"Scanning '{0}'",path); } }
Alle Antworten
-
Donnerstag, 12. April 2012 02:28Besitzer
Hi Matthew - I think this is because 'app.config' is a VS concept while the Roslyn Workspace APIs (i.e. IWorkspace, IProject, ISolution) only represent the view of solutions, projects, documents that the C# and VB language services consume.
Take a look at Dustin's answer on this thread about another VS feature (i.e. nested docuements) that is not supported in the Workspace APIs. I think his answer would also apply to this thread. Also take a look at this thread about folder reference paths which is another VS concept that is currently not supported by the Workspace API.
Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team
-
Donnerstag, 12. April 2012 15:05
This is a really weak answer given that the Workspace functionality is based around loading a Visual Studio solution. I would think that if I can load a Visual Studio solution file as the starting point I should at least be able to list all of the files referenced by the solution and all projects contained within. If that is not the intended usage, why is it a possibility?
-
Donnerstag, 12. April 2012 20:05Besitzer
Hi Matthew,
As I stated in the other thread, the Workspace is intended to provide a view of solutions, projects and documents that is actually used by C# and Visual Basic. The notion of an IDocument is tied very strongly to Roslyn APIs. For example, what would IDocument.GetSemanticModel() return for an app.config file (bearing in mind that Roslyn strictly scoped to C# and VB -- not XML)? Also, what <ItemGroups> would be included? Content? None? Resource? EmbeddedResource? And so on?
To really get this sort of information outside of VS, you should probably just use the MSBuild APIs which already exist in the .NET framework. If you're in VS, you would probably walk the IVsHierarchy and enumerate the project items. If you want to do semantic analysis of C# and VB files, you should use a workspace.
Dustin Campbell | Senior Program Manager | Roslyn Visual Basic and C# Language Services

