如何从2.1到4.1运行PostShard样本?

时间:2015-10-08 22:01:30

标签: postsharp

Download - Samples – PostSharp下载样本后 显示要求安装PostSharp 2.1的“PostSharp Required”对话框。

我的机器上安装了PostSharp 4.1,有没有办法使用PostSharp 4.1运行这些样本?

1 个答案:

答案 0 :(得分:0)

大多数样本应该兼容,但目前尚未得到官方支持。

要将它们转换为新的PostSharp版本,您需要编辑csproj文件,删除以下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>

此外,您需要删除所有引用的PostSharp程序集 - 很可能只有PostSharp.dll(在编辑csproj文件时或重新打开后)。

重新打开项目后,您应该添加PostSharp NuGet包,它将安装当前版本的PostSharp。