Share via


Find the .csproj path of a .cs file programatically using c#

Question

Monday, May 20, 2013 3:48 PM

Is it possible to find the .csproj file associated with a .cs file programatically using C#?

The .cs file being referred here is on TFS.

All replies (2)

Monday, May 20, 2013 3:56 PM ✅Answered

No.  A single .cs file may be contained in multiple .csproj, or no .csproj.

You could use an extension to find all of the .csproj (if any) containing a .cs file.   This would require a VS extension, though: http://msdn.microsoft.com/en-us/library/bb165336.aspx

Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


Monday, May 20, 2013 3:56 PM ✅Answered

A .cs file can be in any number of projects.    A project refers to source files, but source files do not refer to projects.    You can wander around the directories nearby looking for csproj files and then open them up searching for the cs file name you're concerned about.

The proj files are just text (XML) but you really don't even need to parse them to hunt for the file name.