I'm using the Typewriter extension for Visual Studio and Visual Studio 2017. The following is the Typescript Template file.
${
using System.IO;
Template(Settings settings)
{
settings.IncludeProject("ProjectName");
}
string Test(Class c)
{
//return Path.GetDirectoryName(Path.GetDirectoryName( System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ))); // > file:\C:\Users\[user]\AppData\Local
//return Environment.CurrentDirectory; // > C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE
return String.Join(", ", Directory.GetFiles("relative\path")); // > System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\relative\path'.
}
}
$Classes(ProjectName.Models.*)[
export class $Name {
$Properties[
public $Name: $Type;]
// $Test
}]
When using Directory.GetFiles
the path is relative to C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE
not relative to the template file or the project. How can I get relative files?
P.S. Not sure if this is specific to Typewriter or Visual Studio Extensions in general.
Edit
I have since tried DTE:
using EnvDTE;
DTE dte = (DTE)GetService(typeof(DTE));
string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
But I get The type or namespace name 'EnvDTE' could not be found (are you missing a using directive or an assembly reference?)
and i don't how to reference an assembly within an existing extension. If I could use DTE that would resolve the initial question.