Reputation: 13429
I upgraded PostSharp recently via NuGet and it has stopped working, but only in very select cases. It doesn't work on my build server (TeamCity), and it doesn't work on only one of my projects. The other projects all transform correctly.
What might I have changed to lose the PostSharp transform in only one of my projects?
Upvotes: 3
Views: 895
Reputation: 13429
There are two things to check if this happens to you:
First, ensure that both your debug and release configurations do not include the following XML:
<SkipPostSharp>True</SkipPostSharp>
This directive can be present in one or both configurations and if you're like me you only test the latter through your build server.
Second, recent PostSharp versions (at least 2.1.7.28+) have changed how the MSBuild targets are imported into a project, specifically with NuGet. It used to be that PS simply imported the targets, and if the PostSharp targets file didn't exist, the project didn't load. This was a hassle because the project had to load before NuGet could automatically download the targets file.
Now, the import directive looks like this:
<Import Project="..\packages\PostSharp.2.1.7.28\tools\PostSharp.targets"
Condition="Exists('..\packages\PostSharp.2.1.7.28\tools\PostSharp.targets')" />
This is really handy because it means the project can still load before NuGet has done its thing.
Unfortunately, it also means when you first load the project, the PostSharp targets will not be loaded. And on TeamCity, for some reason - even with "Clean all files before build" unchecked - it never loaded those targets.
Checking the following files into source control solved the problem:
Finally, as a precaution, I definitely recommend some runtime test (eg. unit tests) that ensure PostSharp has properly transformed everything you expect. For each project that uses a PostSharp aspect, consider a unit test like this:
Assert.That(MyProject.IsTransformedByPostSharp, Is.True);
where the property IsTransformedByPostSharp
simply checks the Post.IsTransformed
property.
Upvotes: 6