Search code examples
visual-studioproject-template

Create Visual Studio project template with custom targets file import


We use external API that can change versions, so we created target file where it is easy to switch which version of the API is included. Import looks like this:

<Import Project="$(ExternalDir)API\Api.References.All.Latest.targets" />

It is a pain to create a new project now because you need to edit it manually to include the targets file, so I am trying to create a project template. I used File->Export Template to create a new template from existing project. But when I try to create a project using that template I get following error:

C:\Users\name\AppData\Local\Temp\yuavfizw.xis\Temp\TestProject.csproj: The imported project "C:\Users\name\AppData\Local\Temp\yuavfizw.xis\Temp\API\Api.References.All.Latest.targets" was not found.

$(ExternalDir) is defined in another targets file that is imported to the same project. The import is also present in the project template. Import looks like this:

<Import Project="..\constants.*.targets" />

Is there any way to work around this error?


Solution

  • There is a project template setting, that fixes this issue:

    <CreateInPlace>true</CreateInPlace>