Is it possible to select which projects PostSharp processes instead of telling it which to exlude?
Asked Answered
P

1

5

I can specify the SkipPostSharp constant to ensure a project is excluded from the list of projects PS processes. I want to do it the other way around though. I want PS to assume it shouldn't process anything that I don't specifically tell it to.

Is this achievable?

Porphyria answered 21/3, 2012 at 23:59 Comment(0)
F
15

There are three conditions for a project to be automatically processed by PostSharp:

  1. PostSharp has been installed using the setup program.
  2. The project has a reference (direct or indirect) to PostSharp.dll.
  3. The MSBuild property SkipPostSharp is different than true and the compilation symbol SkipPostSharp is undefined.

The third condition is what becomes false when you disable PostSharp by checking the option in VS project properties.

You could disable PostSharp by default by setting the SkipPostSharp=True property by default. This can be achieved by creating a file named PostSharp.Custom.targets in one of the parent directories of your projects, with the following content:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
     <SkipPostSharp Condition="'$(SkipPostSharp)'==''">True</SkipPostSharp>
  </PropertyGroup>
</Project>

Then, in every project where PostSharp is actually needed, you would need to define the property SkipPostSharp=False. You will have to do that using a text editor, because the project property tab only allows to set the property to True or to undefine it.

Follow answered 22/3, 2012 at 16:20 Comment(7)
Just for clarification... If I have a directory called 'SourceCode' that all my project directories reside in, then I could create the PostSharp.Custom.targets file in that folder and any new projects that other people create will not automatically use post sharp even if they reference other projects that do. Is that correct?Porphyria
Assuming their projects go into the SourceCode folder, of course.Porphyria
This is documented here: doc.sharpcrafters.com/postsharp-2.1/Content.aspx/…. Basically, PostSharp will look in parent directories of the project file, so you the file can be shared among several projects and solutions.Follow
Thanks Gael... for being awesome.Porphyria
If you want to edit the project file in VisualStudio, you can unload the project and then the option should be available to edit. Also, if you install the VisualStudio Power Command extension, it adds a context menu to edit the project file (it simply automates the unloading of the project for you)Electrolier
I've tried adding the 'PostSharp.Custom.targets' file and put in the text as per your answer but this has no effect and PostSharp is still active. Is there anything else I'd need to do (change Build Action etc.) or does this no longer apply to the latest version of PostSharp?Superdreadnought
SkipPostSharp should still work in the latest version. It's sometimes difficult to debug MSBuild. Try to deliberately make your PostSharp.Custom.targets file an invalid XML file to see if MSBuild even tries to load it.Follow

© 2022 - 2024 — McMap. All rights reserved.