T4MVC / R4MVC

R4MVC is a Roslyn code generator for ASP.NET Core MVC apps that creates strongly typed helpers that eliminate the use of literal strings in many places
Apache License 2.0
159 stars 48 forks source link

Find the root folder on disk of the project hosting R4MVC #5

Closed kevinkuszyk closed 7 years ago

kevinkuszyk commented 9 years ago

We need to find where on disk the project.json file is for the project hosting R4MVC, so we write out our generated .cs files.

At the moment it is hard coded here.

wwwlicious commented 9 years ago

Unfortunately the project object isn't on the interface for IBeforeCompileContext but is does exist via some casting against the Concrete type

CompileContext context = ((CompileContext)context);
var rootFolder = Path.GetDirectoryName(context?.Project.ProjectFilePath)

Example here

An alternative might be get the FilePath from a syntax tree and work it out using that

artiomchi commented 7 years ago

That issue seems to be obsolete/unnecessary at this point, since writing generated.cs files is now working.

If getting the root path for the project is necessary in other scenarios, it can easily be picked up from the Workspace's Project properties