我解決了這個沒有太多的犛牛剃鬚。很明顯的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#來說是一個非常可靠的方法 - 它包含了引用的程序集,嵌入式資源和內容。