Another approach is to modify the <Import> element in question to make it conditional, for example:
<Import Project="$(CodeAssassinTargets)" Condition="Exists($(CodeAssassinTargets))" />
It depends on the new property defined in the previous <PropertyGroup> . Usually I add one of them to the top of the csproj file with other "global" flags, for example:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <CodeAssassinTargets>$(SolutionDir)packages\CodeAssassin.ConfigTransform.1.1\tools\CodeAssassin.ConfigTransform.targets</CodeAssassinTargets> <AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings> <UseMsdeployExe>true</UseMsdeployExe> </PropertyGroup>
Then, for the appropriate purpose, such as BeforeBuild, you will receive a useful error message:
<Target Name="BeforeBuild"> <Error Text="CodeAssassin.ConfigTransforms target is missing. It needs to exist at $(CodeAssassinTargets) in order to build this project!" Condition="!Exists($(CodeAssassinTargets))" /> </Target>
With these changes, the project will be loaded even if the restoration of the nuget package has never been completed. If automatic package recovery is enabled, the first build attempt should clear the missing target problem, but if it is not, one manual package recovery will be.
source share