1

Using the Roslyn (Microsoft.CodeAnalysis) APIs, how do I get the Build Action and Copy to Output Directory File Properties? I'm able to open the project file and get the documents, but not sure how to get the file properties.

enter image description here

Opening the project and looping over the filesis easy enough. I just want to know what the build action is of each.

    open Microsoft.CodeAnalysis.MSBuild

    use ws = MSBuildWorkspace.Create()
    let pr = ws.OpenProjectAsync proj |> Async.RunTask
    for doc in pr.Documents do
        printfn "file %s" doc.FilePath
Cameron Taggart
  • 5,771
  • 4
  • 45
  • 70
  • 2
    It's something that's handled by msbuild, and not the csc. The compiler itself only knows about the source files, references, and resources. If you are inside VS, you could probably use the VS SDK to grab that information, like [here](https://social.msdn.microsoft.com/Forums/vstudio/en-US/bd74f1bc-2c60-4f9c-b29f-e50bf16aadfc/using-dte-to-set-a-custom-build-action?forum=vsx). Also, check out [this answer](http://stackoverflow.com/questions/12367945/roslyn-add-a-document-to-a-project/12370901#12370901) from an old SO thread. – Tamas Nov 10 '15 at 12:59

2 Answers2

2

Roslyn's API doesn't surface things the compiler doesn't care about or need for language analysis. In this case you'll want to use the MSBuild APIs directly.

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55
1

Here's one way to retrieve the item type (also known as build action) of an item with just the project id (Guid from Roslyn's ProjectId.Id) and the Document.FilePath: http://www.cazzulino.com/item-type-from-file.html

kzu
  • 1,795
  • 15
  • 16