I’ve create a project template which contains a csproj which contains an Import pointing to a project file where I list all the third party project locations. I’m always using this project template to create projects in the same relative directory.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="../../../3rdParty/ThirdParty.targets" />
...
<ItemGroup>
<Reference Include="Library, Version=$(LibraryVersion), Culture=neutral, PublicKeyToken=$(LibraryPublicKeyToken), processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(LibraryDir)LibraryDll.dll</HintPath>
</Reference>
</ItemGroup>
...
</Project>
The csproj file works properly in Visual Studio and when running msbuild from the command prompt. When I try to create a project using the project template I get the following error:
C:\Users…\AppData\Local\Temp\534cylld.o0p\Temp\MyModule.csproj(3,3): The imported project “C:\Users…\AppData\Local\3rdParty\ThirdParty.targets” was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
It seems that Visual Studio is trying to open the project in a temporary location first.
I’ve tried adding $(MSBuildProjectDirectory) to the import location hoping that it might force it to use the location I intended, but that also didn’t work.
Any suggestions?
You should set the CreateInPlace property to
truein the vstemplate. The documentation saysIf you want relative paths to work, you need the parameter replacement to occur in the place where you’re creating the project, not in a temporary location.