开发者

Adding a new target type to msbuild: How do I refer to the itemname in the task rules?

I'm trying to add a task to build the COM proxy DLL after building the main DLL. So I created the following in a .target file:

<Target Name="ProxyDLL"
      Inputs="$(IntDir)%(WHATGOESHERE)_i.c;$(IntDir)dlldata.c"
      Outputs="$(OutDir)%(WHATGOESHERE)ps.dll"
      AfterTargets="Link">
   <CL Sources="$(IntDir)%(WHATGOESHERE)_i.c;$(IntDir)dlldata.c" />
</Target>

And reference it from the .vcxproj file as

<ItemGroup>
  <Proxy开发者_如何学编程DLL Include="FTAccountant" />
</ItemGroup>

So the FTAccountant.DLL file is created through the normal build process and then when attempts to compile the proxy stubs it creates these command lines:

cl /c dir\_i.c dir\dlldata.c

And of course it can't find _i.c. The first attempt, I put %(Filename) in the WHATGOESHERE space and I got this error:

C:\ActivePay\Build\Proxy DLL.targets(6,3): error MSB4095: The item metadata
%(Filename) is being referenced without an item name.  Specify the item name by
using %(itemname.Filename).

So I changed it to %(itemname.Filename) and that is an empty string. How to get the value specified in the task's Include attribute and use it within the task?


You must specify the element whose value you want :

<ItemGroup>
  <COMProxy Include="FTAccountant" />
</ItemGroup>

<Target Name="ProxyDLL"
      Inputs="$(IntDir)%(COMProxy.Identity)_i.c;$(IntDir)dlldata.c"
      Outputs="$(OutDir)%(COMProxy.Identity)ps.dll"
      AfterTargets="Link">
   <CL Sources="$(IntDir)%(COMProxy.Identity)_i.c;$(IntDir)dlldata.c" />
</Target>


I finally figured this out. I needed to put an additional target on the project's Project tag:

<Project Targets="Build;ProxyDLL" ...>

The above ProxyDLL target never worked. So I ended up just create a separate project for the proxy DLL and calling that with the MSBuild task. Since this is now called from within the context of an existing project, the ProjectName variable is available:

<Target Name="ProxyDLL"
        Inputs="$(MyPathVar)$(ProjectName)_i.c"
        Outputs="$(OutDir)$(ProjectName)ps.dll"
        AfterTargets="Link">
   <MSBuild Project="$(MyPathVar)$(ProjectName)ps.vcxproj" />
</Target>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜