我有一個MSBuild腳本我寫信給谷歌編譯Protocol Buffers的文件:(!耶)如何從MSBuild目標修改ItemDefinitionGroup?
<ItemGroup>
<ProtocolBuffer Include="Whitelist.proto" />
<ProtocolBuffer Include="Whitelist2.proto" />
</ItemGroup>
<ItemDefinitionGroup>
<ProtocolBuffer>
<ProtoPath>$(ProjectDir)</ProtoPath>
</ProtocolBuffer>
</ItemDefinitionGroup>
<PropertyGroup>
<ProtoC>$([System.IO.Path]::GetFullPath($(ProjectDir)..\ThirdParty\protobuf-2.4.1\protoc.exe))</ProtoC>
<ProtoOutPath>$(IntDir)CompiledProtocolBuffers</ProtoOutPath>
</PropertyGroup>
<Target Name="CompileProtocolBuffers"
BeforeTargets="ClCompile"
Inputs="@(ProtocolBuffer)"
Outputs="@(ProtocolBuffer->'$(ProtoOutPath)\%(FileName).pb.cc');@(ProtocolBuffer->'$(ProtoOutPath)\%(FileName).pb.h')">
<MakeDir Directories="$(ProtoOutPath)" />
<Exec
Command=""$(ProtoC)" --proto_path="$([System.IO.Path]::GetDirectoryName(%(ProtocolBuffer.ProtoPath)))" --cpp_out="$(ProtoOutPath)" "%(ProtocolBuffer.FullPath)" --error_format=msvs"
/>
<ItemGroup>
<ClInclude Include="$(ProtoOutPath)\%(ProtocolBuffer.FileName).pb.h" />
<ClCompile Include="$(ProtoOutPath)\%(ProtocolBuffer.FileName).pb.cc">
<AdditionalIncludeDirectories>$(MSBuildThisDirectory)..\ThirdParty\protobuf-2.4.1\src</AdditionalIncludeDirectories>
<PrecompiledHeader></PrecompiledHeader>
<DisableSpecificWarnings>4244;4276;4018;4355;4800;4251;4996;4146;4305</DisableSpecificWarnings>
<PreprocessorDefinitions>GOOGLE_PROTOBUF_NO_RTTI</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
</ItemGroup>
</Target>
這編譯協議緩衝區文件完美,並將它們添加到編譯器的輸入。然而,我想要包含.pb.h
文件的其他源文件需要知道這些文件的生成位置 - 生成位置需要放在包含路徑中。
因此,當且僅當用戶已經包括了<ProtocolBuffer
項目的地方在他們的劇本,我想補充的生成位置(在這種情況下$(ProtoOutPath)
到ClCompile的<AdditionalIncludeDirectories>
。
那是可能的,或者我需要使想要使用這些生成的位的.cpp文件跳過循環?
我面臨着同樣的問題(雖然設置'PreprocessorDefinitions'編程而不是' AdditionalIncludeDirectories')。聖牛這是神奇的,但它出奇的好。謝謝! –