I have a solution with many projects, some of which use PostSharp. I've recently switched from using NuGet MSBuild integrated restore to NuGet Auto Restore. This causes all necessary packages to be restored for all packages before a build starts. This works great, except for now I come across an issue frequently where PostSharp will fail the build with the error:
The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore.
When I edit the project file I see the following entry:
<Import Project="..\..\packages\PostSharp.3.1.46\tools\PostSharp.targets" Condition="Exists('..\..\packages\PostSharp.3.1.46\tools\PostSharp.targets')" />
<Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
<Error Condition="!Exists('..\..\packages\PostSharp.3.1.46\tools\PostSharp.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://www.postsharp.net/links/nuget-restore." />
<Error Condition="Exists('..\..\packages\PostSharp.3.1.46\tools\PostSharp.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore." />
</Target>
As you can see, there is an error condition for when the NuGet package exists on my machine and also doesn't exist on my machine. It appears that these conditions are evaluated because the variable $(PostSharp30Imported) is never set. I'm assuming this something that is dependent on the MSBuild integrated version of restore, but I don't have enough MSBuild experience to know for sure.
I am able to work around the issue by simply removing the second Error condition in the project file (since I am guaranteed to have the files by the time the project builds), but it seems like any upgrades or additions of PostSharp cause the project file to revert to the old way and prevents my solution from building.
Is this a bug in PostSharp, or is there some other way I should be working with PostSharp when using NuGet auto restore that does not cause this issue?