The element <TemplateFile> beneath element <Project> is unrecognized

2,014 views
Skip to first unread message

Eugene Dorofeyev

unread,
Jul 15, 2011, 12:36:34 PM7/15/11
to MSBuild Community Tasks
Hello everyone,

I'm trying to use MSBuild Community Tasks to generate C++ header file
with version information.
The script MyApp.msbuild that I'm using looks like following:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks
\MSBuild.Community.Tasks.Targets" />

<ItemGroup>
<Tokens Include="Major">
<ReplacementValue>4</ReplacementValue>
</Tokens>
<Tokens Include="Minor">
<ReplacementValue>5</ReplacementValue>
</Tokens>
<Tokens Include="Version">
<ReplacementValue>6</ReplacementValue>
</Tokens>
<Tokens Include="BuildNumber">
<ReplacementValue>101</ReplacementValue>
</Tokens>
</ItemGroup>

<TemplateFile TemplateFile="Include/Templates/version.h.template"
OutputFile="Include/version.h" Tokens="@(Tokens)" />

<ItemGroup>
<ProjectToBuild Include="MyApp.sln" />
</ItemGroup>

<Target Name="Release">
<MSBuild Projects="@(ProjectToBuild)"
Properties="Configuration=Release" Targets="Rebuild"
BuildInParallel="True" />
</Target>
<Target Name="Debug">
<MSBuild Projects="@(ProjectToBuild)"
Properties="Configuration=Debug" Targets="Rebuild"
BuildInParallel="True" />
</Target>
<Target Name="BetaRelease">
<MSBuild Projects="@(ProjectToBuild)"
Properties="Configuration=BetaRelease" Targets="Rebuild"
BuildInParallel="True" />
</Target>
<Target Name="BetaDebug">
<MSBuild Projects="@(ProjectToBuild)"
Properties="Configuration=BetaDebug" Targets="Rebuild"
BuildInParallel="True" />
</Target>
</Project>

When I try to build the project from the command line using MSBuild
4.0.30319.1 I constantly get the following error:

MyApp.msbuild(19,5): error MSB4067: The element <TemplateFile> beneath
element <Project> is unrecognized

I'm using the stable build of MSBuild.Community.Tasks.msi, and also I
tried using the latest nightly build version 1.3.0.514. In both cases
the result is the same.

I also tried to play with variable $(MSBuildExtensionsPath) by
replacing it with $(MSBuildExtensionsPath32) or even with absolute
path to file MSBuild.Community.Tasks.Targets. Didn't help either.

When I wrap <TemplateFile> with another <Target> element, MSBuild
produces error like:

MyApp.msbuild(20,23): error MSB4064: The "TemplateFile" parameter is
not supported by the "TemplateFile" task. Verify the parameter exists
on the task, and it is a settable public instance property.

I suspect that I'm missing some small detail or may be the
installation of MSBuild Community Tasks went wrong so that MSBuild
simply doesn't see Community Tasks targets.

My operating system is Windows 7 Ultimate.

Any help will be appreciated.

Thanks

Eugene Dorofeyev

unread,
Jul 18, 2011, 5:23:01 AM7/18/11
to MSBuild Community Tasks
No one did answer but I figured out by myself.

First of all, <TemplateFile> should reside within <Target> element.
Maybe it is obvious for people who have an experience with MSBuild but
not for MSBuild-noobs like me.

Second, it turns out that the error message

> MyApp.msbuild(20,23): error MSB4064: The "TemplateFile" parameter is
> not supported by the "TemplateFile" task. Verify the parameter exists
> on the task, and it is a settable public instance property.

clearly states what is wrong. Indeed, in the documentation (.chm file
shipped by the installation package) at the TemplateFile Class page
there's example:

<ItemGroup>
<Tokens Include="Name">
<ReplacementValue>MSBuild Community Tasks</ReplacementValue>
</Tokens>
</ItemGroup>

<TemplateFile TemplateFile="ATemplateFile.template"
OutputFile="ReplacedFile.txt" Tokens="@(Tokens)" />

However, when one looks at the TemplateFile Members page the
corresponding property is named Template instead of TemplateFile.
Also, in my case I replaced OutputFile with OutputFilename. So, my
correct line is:

<TemplateFile Template="Include\Templates\version.h.template"
OutputFilename="..\version.h" Tokens="@(Tokens)" />

It also processes file paths in a little bit strange way.
OutputFilename becomes relative to Template filename. When I first
specified

<TemplateFile Template="Include\Templates\version.h.template"
OutputFilename="Include\version.h" Tokens="@(Tokens)" />

MSBuild Community Tasks tried to open file like $(SolutionDir)Include
\Templates\Include\version.h instead of $(SolutionDir)Include
\version.h. The file didn't exist and MSBuild CT failed so that I had
to prepend '..\' to header's filename.

I guess it would be great if MSBuild Community Tasks will be able to
create directory structure and the target file in case if it doesn't
exist.
Reply all
Reply to author
Forward
0 new messages