Get files other than .cs with Roslyn

I want to find ways to use the Roslyn method. I managed to do this for use by code in .cs files. In addition, I want to parse the JavaScript files included in the solution. I know that Roslyn cannot parse JavaScript syntax or semantics, so I only want to look for the textural occurrencies my method name in all .js files.

I extract all files (documents) as follows:

 foreach (Project pr in solution.Projects) { foreach (Document doc in pr.Documents) { // my js-file is not included } } 

But Documents contains only .cs files. Is there a way to get the .js files, or do I need to get the folder with project.FilePath and get the files with the old File API , which can cause problems, because not all files in the folder need to be added to the project, etc.

Edit:
In addition, AdditionalFiles does not contain any files.

+6
source share
1 answer

You need to use Project.AdditionalDocuments :

 foreach (Project pr in solution.Projects) { foreach (TextDocument doc in pr.AdditionalDocuments) { // doc is a non-csharp TextDocument object. } } 

Update

To use the above, you must ensure that the file in the target project has the build action set to AdditionalFiles . There is currently no good way to generate a file in the target project using an action to create this type, so you are currently obsessed with relying on the user of your code by manually stubbing the file, pressing F4 for the file properties and changing its action builds on AdditionalFiles , after which your extension will be able to raise it.

Additional files

+2
source

All Articles