我創建了一個自定義的.targets文件,如下(只是添加了所有在myproj.vcxproj文件要求.targets文件中的常見任務)定製.targets文件不工作
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- *******************************************************************************************
Common tasks
******************************************************************************************* -->
<Target Name="H1">
<Exec Command="del /F/Q @(S_PACK_H1)" />
<RemoveDir Directories="@(D_PACK_H1)" />
</Target>
<Target Name="H2">
<Exec Command="del /F/Q @(S_PACK_H2)" />
<RemoveDir Directories="@(D_PACK_H2)" />
</Target>
<Target Name="H11">
<Exec Command="del /F/Q @(S_PACK_H11)" />
<RemoveDir Directories="@(D_PACK_H11)" />
</Target>
</Project>
所有宏/陣列狀S_PACK_H1,D_PACK_H11在myproj.vcxproj文件中定義之後,我在myproj.vcxproj文件,如下
<Import Project="C:\Program Files\MSBuild\MyCompany\Mycustom.targets" />
導入此,當我用下面的CMD
的MSBuild myproj.vcxpr OJ /噸:H11
它提供了一個錯誤「錯誤MSB4057:目標‘H11
’不會在項目存在」,但如果我有.vcxproj文件,而不是.targets相同的任務列表文件然後它工作正常。
我可以在.vcxproj文件中定義宏並在.targets文件中使用它們嗎? MSBuild能夠獲得該定義/值嗎?如果沒有,那麼我該如何去使用/傳遞在.targets文件中定義的vxcproj文件中的東西?
爲什麼msbuild在.targets文件中無法看到我的任務Vs .proj文件?我還需要做什麼?