mavnn
mavnn

Reputation: 9469

Can MsBuild (command line or library) create a list of referenced files?

As part of a build of a complex system I would like to know which files have been referenced as part of a .net project file build. In theory this could be read from the XML, but once you start taking properties and conditional nodes into account it's a non-trivial task.

In the same way that gcc -MM can give you a list of c header files, is there a way to obtain the list of resolved references (project and dll) from MsBuild? From the command line would be ideal, but via the MsBuild libraries would also be a possibilty.

Upvotes: 1

Views: 296

Answers (1)

mavnn
mavnn

Reputation: 9469

It turns out with can be done using the MsBuild common targets and a wrapper project.

Create a file like this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="WriteStuff" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(TargetProject)"/>
  <Target Name="WriteStuff" DependsOnTargets="ResolveReferences">
    <Message Importance="high" Text="References::@(ReferencePath)"/>
    <Message Importance="high" Text="Compiles::@(BeforeCompile);@(Compile);@(AfterCompile)"/>
    <Message Importance="high" Text="Output::$(OutputPath)"/>
  </Target>
</Project>

And build it with MsBuild with the "/p:TargetProject=yourproject.proj" property set.

It will output a list of all the referenced dlls, compilation files and the output directory.

There's a few more details at http://blog.mavnn.co.uk/extracting-information-from-msbuild/

Upvotes: 2

Related Questions