You cannot call a target before importing goals, but you can still dynamically generate a path to import from a group of properties.
Visual Studio does this when creating a web project, as in this example from one of my projects:
<PropertyGroup> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> </PropertyGroup> <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" />
This way you can definitely define properties using conditions:
<PropertyGroup> <ImportPath Condition="Exists('path\to\some\thing.targets')">path\to\some\thing.targets</ImportPath> </PropertyGroup> <Import Project="$(ImportPath)" Condition=" '$(ImportPath)' != '' "/>
Microsoft.Bcl.Build does this, so you can too.
source share