Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
最近,我一直在使用PostSharp。它是一个 AOP 框架,允许我们进行编译时代码注入。您可以只引用 PostSharp 程序集,在您的代码中使用它,编译后,您将获得一个已将所需代码注入其中的程序集。我试图找出 PostSharp 是如何将自己集成到 Visual Studio 的编译过程中并更改代码的,但直到现在还没有结果。
有没有办法让 Visual Studio 在编译期间或之后运行一些代码,而不使用项目的后期构建任务或任何插件?
魔法在最后一行C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets。这会加载一个文件c:\Program Files\MSBuild\v3.5\Custom.After.Microsoft.Common.targets(如果存在)。
C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets
c:\Program Files\MSBuild\v3.5\Custom.After.Microsoft.Common.targets
因此 PostSharp 在安装期间编辑此文件并添加对其自己的目标文件的引用。