Search code examples
c#command-linevisual-studio-2015postsharpsystem-codedom-compiler

Is it Possible to add PostSharp for dynamic compilation using c# compiler


I am using Microsoft.CodeDom.Providers.DotNetCompilerPlatform nuget packge for compilation of code at runtime. It is achievable but in my scenario my dynamic class needs to use Postsharp for aspect oriented programming.

Can anyone point me to the commandline support to add Postsharp dependency injection for the compiled assembly using the csc.exe, like what is done by the MSBuild or Visualstudio.


Solution

  • You can't easily do that with the current versions of PostSharp. The last version to have command-line execution is 5.0 and that is no longer supported.

    The problem is that PostSharp reads too many properties in MSBuild or passed to it by MSBuild.

    If it's possible for you to generate an msbuild file, you can then build it the Microsoft.Build NuGet package and have PostSharp run on the generated code that way.