Search code examples
postsharp

How to run PostShard samples from 2.1 to 4.1?


After download samples from Download - Samples – PostSharp a "PostSharp Required" dialog was shown asking to install PostSharp 2.1.

I have PostSharp 4.1 installed in my machine, is there a way to run those samples using PostSharp 4.1?


Solution

  • Most samples should be compatible, but are not currently officially supported.

    To convert them to the new PostSharp version, you need to edit the csproj file remove the following XML:

    <!-- The next section automatically prompts you to install PostSharp if needed. It is not required in normal projects. -->
    <UsingTask AssemblyFile="lib\PostSharp.MSBuild.Samples.exe" TaskName="PostSharp.MSBuild.Samples.LaunchPostSharpInstaller"  />
    <Target Name="PostSharp21Check" Condition="'$(PostSharp21Imported)'==''" >
        <LaunchPostSharpInstaller ProjectPath="$(MSBuildProjectFullPath)" Version="2.1" ProjectGuid="$(ProjectGuid)" BuildingProject="$(BuildingProject)" />
        <Error Text="To build this project, you must install PostSharp 2.1 on your machine or add it as a NuGet package to this project." />
    </Target>
    <PropertyGroup >
        <ResolveReferencesDependsOn>PostSharp21Check;$(ResolveReferencesDependsOn)</ResolveReferencesDependsOn>
    </PropertyGroup>
    

    Additionally, you need to remove all referenced PostSharp assemblies - most likely only PostSharp.dll (either when editing the csproj file or after reopening).

    After reopening the project, you should add PostSharp NuGet package, which will install the current version of PostSharp.