2011-10-21 29 views
1

有沒有辦法強制MsBuild以類似於makedepend的結構化格式輸出目標相關性信息?我在解決方案級別需要這樣的解決方案,其中包含C#和C++項目。我對輸出格式不挑剔。MsBuild可以輸出與makedepend相似的依賴信息嗎?

我認爲可以通過處理.csproj文件和構建DAG來確定C#依賴關係。同樣,我可以在C++源代碼上運行一個開源的makedepend,然後從那裏開始。我真的不想在這裏推出自己的產品 - 這似乎是MsBuild應該能夠做的事情,即使是出於診斷目的。

回答

1

我解決了這個沒有太多的犛牛剃鬚。很明顯的MSBuild確實有建那麼我的做法是與寫入依賴於.depends文件的自定義目標包裹在生成過程中的依賴性信息:

<?xml version="1.0" encoding="utf-8"?> 
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 

    <!-- Write project dependencies to a .depends file, one line per dependency --> 
    <Target Name="OutputProjectDependencies"> 
    <Delete Files="$(OutputPath)\$(TargetFileName).depends"/> 
    <WriteLinesToFile File="$(OutputPath)\$(TargetFileName).depends" 
     Lines="@(CscDependencies->'%(FullPath)');@(ReferencePath->'%(FullPath)');@(Content->'%(FullPath)');@(_NoneWithTargetPath->'%(FullPath)')" 
     Overwrite="false" 
     Encoding="UTF-8"/> 
    <WriteLinesToFile File="$(OutputPath)\$(TargetFileName).depends" 
     Lines="@(ClDependencies->'%(FullPath)')" 
     Overwrite="false" 
     Encoding="UTF-8"/> 
    </Target> 

    <ItemGroup> 
    <CscDependencies Include="@(Compile);@(EmbeddedResource)"/> 
    <ClDependencies Include="@(ClCompile);@(ClInclude)"/> 
    </ItemGroup> 

    <PropertyGroup> 
    <BuildDependsOn> 
     $(BuildDependsOn); 
     OutputProjectDependencies; 
    </BuildDependsOn> 
    </PropertyGroup> 

</Project> 

這是不太一樣強大,我想對於C++項目(它沒有包含頭文件和鏈接庫依賴項),但可能會進一步增強。我相信這對於C#來說是一個非常可靠的方法 - 它包含了引用的程序集,嵌入式資源和內容。

相關問題