This section explains how to upgrade from a previous version of PostSharp.
Tip
Other sections of this chapter, specifically Installing Visual Studio Tools for Metalama and PostSharp, Deploying License Keys and Using PostSharp on a Build Server, are also useful if you need to upgrade from an earlier version of PostSharp.
Upgrading Visual Studio Tools for Metalama and PostSharp
After you install Visual Studio Tools for Metalama and PostSharp, you will still be able to open solutions that use older versions of PostSharp.
Visual Studio Tools for Metalama and PostSharp are backward compatible with older versions of PostSharp. However, several versions of the extension cannot coexist. Therefore, installing a new version of PostSharp Tools will uninstall the previous version.
To upgrade Visual Studio Tools for Metalama and PostSharp, simply download it from https://www.postsharp.net/download and execute the installation package.
Caution
Upgrading Visual Studio Tools for Metalama and PostSharp does not implicitly upgrade your source code.
Upgrading solutions from PostSharp 3 or later
Caution
Before you upgrade your project to a different major release of PostSharp, check that the new version still supports your version Visual Studio and the target framework of your application. Check the release notes for an accurate compatibility list of the specific version you are installing.
You can use several versions of PostSharp side-by-side on the same machine. However, it is recommended that you use the same version in all projects of the same solution.
To upgrade a solution from PostSharp 3 or later:
Open the Solution Explorer in Visual Studio.
Right-click on the solution.
Click on Manage NuGet Packages for Solution.
Click on Updates.
Find the PostSharp package and click on Update.
Select all projects, click OK.
Repeat the operation for all PostSharp.Patterns.* packages.
Upgrading large repositories
If your source contains a large number of solutions, upgrading manually using NuGet may be too labor intensive. In this situation, it is better to use our upgrade PowerShell script.
To upgrade a large number of solutions with the PowerShell script:
Download the following Git repository: https://github.com/sharpcrafters/PostSharp.Utilities. You can download it manually from the web page or execute the following command:
git clone https://github.com/sharpcrafters/PostSharp.Utilities.git
Follow instructions on in README.md.
Warning
This script does not support other platforms than the .NET Framework and does not support PostSharp Pattern Libraries.
Upgrading solutions from PostSharp 2
Every project can have only references to a single version of PostSharp. This applies both to direct and indirect references. The PostSharp 3 or later compiler is not backward compatible with PostSharp 2, and PostSharp 3 will refuse to compile projects that have a reference to PostSharp 2. Therefore, you will typically use a single version of PostSharp in every solution.
You can upgrade projects from PostSharp 2 to PostSharp 3 by adding the PostSharp NuGet package to these projects.
To upgrade a solution from PostSharp 2:
Open the Solution Explorer in Visual Studio.
Right-click on the solution.
Click on Manage NuGet Packages for Solution.
Click on Online.
In the search box, type
PostSharp
. You may want to select the Select prereleases option (instead of the default Stable Only) to install a pre-release version of PostSharp.Find the PostSharp package and click on Install.
Select all projects, click OK.
Although PostSharp 3 or later is mostly backward compatible with PostSharp 2 at source-code level, you may need to perform small adjustments to your source code:
Every occurrence of the _Assembly interface has been replaced by the Assembly classes. You may have to change the signatures of some methods derived from AssemblyLevelAspect.
Aspects that target Silverlight, Windows Phone or Windows Store must be annotated with the PSerializableAttribute custom attribute.
PostSharp Toolkits 2.1 need to be uninstalled using NuGet. Instead, you can install PostSharp Pattern Libraries 3 from NuGet. Namespaces and some type names have been changed.