Search code examples
postsharp

Get the project path/output path during Postsharp compile time


Is it possible to find out the project folder/project file or output path of the assembly during compile time in Postsharp, i.e. during CompileTimeInitialize for example, when the assembly is being built?


Solution

  • You can find out the path to the current project file by evaluating the 'MSBuildProjectFullPath' property during compile time:

    public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo)
    {
        string projectPath =
            PostSharpEnvironment.CurrentProject
                .EvaluateExpression("{$MSBuildProjectFullPath}");
    }
    

    The list of some other PostSharp properties can be found on this documentation page.