Search code examples
nugetpostsharp

Deploying PostSharp into a Source Repository with NuGet Package Restore


Is it possible to Deploy PostSharp into a Source Repository in conjunction with NuGet Package Restore? I can get this working by committing the postsharp package, but that negates somewhat the value of the Package Restore feature.

Here’s what I did.

I see this in my csproj

<Import Project="..\packages\PostSharp.2.1.6.13\tools\PostSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

(I re-ordered them to no avail)

And my build server (CC.net) reports the following errors:

D:\wwwroot\www.snip.co.nz\http\www.snip.co.nz.csproj (714,3):

errorMSB4019: The imported project     "D:\wwwroot\www.snip.co.nz\packages\PostSharp.2.1.6.13\tools\PostSharp.targets" was not found. Confirm that the path in the &lt;Import&gt; declaration is correct, and that the file exists on disk.

CacheAttribute.cs (8,7):
errorCS0246: The type or namespace name 'PostSharp' could not be found (are you missing a using directive or an assembly reference?) 
…etc…

Solution

  • You currently (v2.1.6.13) have to fix the csproj to support Package Restore, within the Import target element add the condition shown here:

    <Import Project="..\packages\PostSharp.2.1.6.13\tools\PostSharp.targets"  
         Condition="Exists('..\packages\PostSharp.2.1.6.13\tools\PostSharp.targets')" />