Installing PostSharp without NuGet

The most common way to add PostSharp to your project is by installing PostSharp NuGet packages. The main benefit of using NuGet Package Manager is that it provides a standard way to install and manage all dependencies for your .NET projects. NuGet, however, also comes with some disadvantages that are inherent in its design (as described by NuGet team in the post NuGet: Broken By Design):

  • hard-coded dependency versions inside project files;

  • more frequent merge conflicts in project files;

  • unexpected and unwanted auto-upgrades of the dependencies;

  • additional overhead in software configuration management;

  • the lack of global package installation option.

For some development teams these NuGet disadvantages become a significant obstacle for NuGet adoption in their projects. This is especially true when strict dependency versioning policies are in place.

If using NuGet Package Manager in your project is not a viable option, then you can install PostSharp without NuGet by following the procedures described in this article. The first time you want to add PostSharp to a project without NuGet, you must first enable PostSharp installation without NuGet. Then, you can specify a folder on your hard drive where PostSharp files will be copied. The next time you will add PostSharp to a project, the same folder can be used.

This topic contains the following sections:

Adding PostSharp without NuGet into a first project in a solution

This is the procedure to install the PostSharp package into a new folder on your computer and reference this package from your project. If you have an existing PostSharp installation, see Sharing the same PostSharp installation folder in several solutions.

To install PostSharp into a folder without NuGet:

  1. By default, PostSharp is always installed using NuGet Package Manager. To change this option, on the PostSharp menu in Visual Studio, click Options, then on the General page of the options dialog select the check box "Always ask before using NuGet Package Manager".

    No Nu Get 1
  2. Right click on your project in the solution explorer and then click "Add PostSharp to Project". The PostSharp package installation wizard opens.

  3. On the first page of the wizard click "Install PostSharp <version> into a new folder and reference it".

    No Nu Get 2
  4. Set the "Path to PostSharp folder". The PostSharp package will be unpacked into this folder. The installer does not overwrite the contents of the target folder, so you need to delete the folder contents if you want to replace the existing installation.

  5. Change the additional installation options, if needed:

    • Store relative path - indicates whether to store relative or absolute paths for PostSharp references and imports in your project files. By default, the relative paths are stored.

    • Use the same options for all projects in the current solution - if enabled, the path to the PostSharp package folder is stored in the <SolutionName>.pssln file. Next time you add PostSharp to another project in the same solution, the package path will be reused and you won’t need to type it again. Disable this option if projects in your solution need to reference different versions of PostSharp package (not recommended).

  6. Click Next and finish the wizard.

As a result of this procedure:

  • the PostSharp files will be copied into the selected folder;

  • the PostSharp assembly reference will be added to your project;

    No Nu Get 4
  • the PostSharp.targets file import will be added to your project file.

    <Import Project="..\..\..\postsharp\Tools\PostSharp.targets" />
  • your installation options will be stored in the MySolution.pssln file (given you have a solution file named MySolution.sln).

    <Property Name="PostSharpPackageManager" Value="Folder" />
    <Property Name="PostSharpRootPath" Value="..\lib\PostSharp" />
Adding PostSharp to a second or next project in the same solution

By default, PostSharp will use installation options stored in the MySolution.pssln file. It means that by default, all projects in the same solution will use the same PostSharp installation folder. PostSharp will not show the wizard page asking about the installation method.

If you want to specify different installation options for the next time you will add PostSharp to a project of this solution, edit the MySolution.pssln file and remove the two following properties: PostSharpPackageManager and PostSharpRootPath.

The next time you will try to install PostSharp, the wizard will now include the page asking about the installation method.

Sharing the same PostSharp installation folder in several solutions

Once PostSharp is copied to any folder of your machine, you can use it in any project or solution.

To add PostSharp to a project and reference an existing PostSharp folder:

  1. Right click on your project in the solution explorer and then click "Add PostSharp to Project". The PostSharp package installation wizard opens.

  2. On the first page of the wizard click "Reference an existing PostSharp folder".

    No Nu Get 3
  3. Set the "Path to PostSharp folder". The path must point to the root folder of the PostSharp package. This is a folder that contains lib and tools sub-folders.

  4. Change the additional installation options, if needed:

    • Store relative path - indicates whether to store relative or absolute paths for PostSharp references and imports in your project files. By default, the relative paths are stored.

    • Use the same options for all projects in the current solution - if enabled, the path to the PostSharp package folder is stored in the <SolutionName>.pssln file. Next time you add PostSharp to another project in the same solution, the package path will be reused and you won’t need to type it again. Disable this option if projects in your solution need to reference different versions of PostSharp package (not recommended).

  5. Click Next and finish the wizard.

As a result of this procedure:

  • the PostSharp assembly reference will be added to your project;

    No Nu Get 4
  • the PostSharp.targets file import will be added to your project file.

    <Import Project="..\..\..\postsharp\Tools\PostSharp.targets" />
  • your installation options will be stored in the MySolution.pssln file (given you have a solution file named MySolution.sln).

    <Property Name="PostSharpPackageManager" Value="Folder" />
    <Property Name="PostSharpRootPath" Value="..\lib\PostSharp" />
Removing PostSharp from a project without NuGet

This is the procedure to uninstall PostSharp from your project if you have previously installed PostSharp package into your project without NuGet.

To uninstall PostSharp without NuGet:

  1. Open the properties window for your project in Visual Studio.

  2. On the PostSharp page of the properties window click "Remove PostSharp from this project" and follow the wizard.

    No Nu Get 5

As a result of this procedure:

  • the PostSharp assembly reference will be removed from your project;

  • the PostSharp.targets file import will be removed from your project file.

Updating PostSharp to a newer version

The nice thing about the non-NuGet deployment is that updating PostSharp is so easy: you just have to extract the new zip file into the PostSharp folder. But because we're trying to look serious and complete in this documentation, here is the formal procedure:

To update PostSharp when you are not using NuGet:

  1. Remove all files from the PostSharp folder.

  2. Download the zip distribution from https://www.postsharp.net/downloads (a file named PostSharp-4.x.x.zip)

  3. Extract the zip file into the PostSharp folder.

That's it!

While NuGet Package Manager represents a standard and proven way to manage your .NET project dependencies, you can still find projects where using NuGet is not possible or causes too much overhead. PostSharp supports you by providing an option to install without NuGet.

See Also