PostSharp4.3/Deployment and Configuration/Deployment/Using Post­Sharp on a Build Server/Restoring Packages at Build Time
Restoring Packages at Build Time

NuGet Package Manager has the ability to restore packages from their repository during the build. This allows teams to avoid storing NuGet packages in source repository.

You can restore the PostSharp package at build time as long as the package is restored before MSBuild is invoked to build the project.

The reason is that PostSharp modifies the project file (csproj or vbproj, typically) to include the file PostSharp.targets. This file is required during the build, otherwise PostSharp is not inserted in the build process, and simply does not work. Because of the design of MSBuild, PostSharp.targets must be present when the build starts, so it cannot be restored from the package repository during the same build. The build that triggers the package restore will fail, and subsequent builds will succeed.

This behavior is acceptable on developer workstations. However, on build servers, you must ensure that the packages are restored before the project is built.

NuGet 2.7 and Later

To restore the PostSharp package at build time, add a preliminary step before building the Visual Studio solutions or projects. This step should execute the following command:

NuGet.exe restore MySolution.sln

In this command, where MySolution.sln is the solution for which packages have to be restored.

Please look at the NuGet Command-Line Reference for details.

NuGet 2.0 to 2.6

To restore the PostSharp package at build time, add a preliminary step before building the Visual Studio solutions or projects. This step should execute the following command for every packages.config file in your solution (typically, for every project):

NuGet.exe install packages.config -OutputDirectory SolutionDirectory\packages

In this command, where SolutionDirectory\packages is the directory where the NuGet packages should be installed.

Please look at the NuGet Command-Line Reference for details.

Tip Tip

You can use PowerShell or MSBuild to execute the nuget install command to all packages.config files in your source repository.

See Also