当我从 XML 文件中读取值时,它是正确的,但是当我使用它(作为 rc.exe 的一个选项)时,它是未定义的。我该如何解决?
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Read custom build number from generated XML file -->
<Target Name="ReadCustomVersion" BeforeTargets="ResourceCompile">
<XmlPeek XmlInputPath="$(OutDir)\CustomVersionNumber.xml" Query="/CustomVersion/CustomBuildNumber/text()">
<Output TaskParameter="Result" ItemName="CustomBuildNumber" />
</XmlPeek>
**<!-- Print out the custom build number -- it is correct here -->**
<Message Text="CustomBuildNumber = @(CustomBuildNumber)">
</Target>
<!-- Add version resource -->
<ItemGroup>
**<!-- CustomBuildNumber will not be set here -->**
<ResourceCompile Include="..\..\build\CommonVersionResource.rc">
<AdditionalOptions>/DBUILD_NUMBER=$(CustomBuildNumber) %(AdditionalOptions)</AdditionalOptions>
</ResourceCompile>
</ItemGroup>
</Project>