T4 Get Current Working Directory of Solution

前端 未结 3 1078
慢半拍i
慢半拍i 2021-02-01 06:20

I am using T4 in Visual Studio 2010, and I want to iterate over the files in my solution, however I have found that T4 source generation works in a kind of a sandbox, and the cu

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 06:53

    This is the method I use to get the solution base directory:

    public string GetSolutionDirectory()
    {
        var serviceProvider = this.Host as IServiceProvider;
        var dte = serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
        return System.IO.Path.GetDirectoryName(dte.Solution.FullName);
    }
    

提交回复
热议问题