Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain output files from a MSBuild project

Is it possible to obtain a list all all the output files from a MSBuild project?

In a simple project, I could do something like

<CreateItem Include="$(OutputDir)**\*">
      <Output ItemName="AllOutputs" TaskParameter="Include"/>
</CreateItem>

but my projects are part of a larger build, and all outputs go to a common location, I want to be able to exculde dlls and content that don't belong.

Any ideas?

like image 265
Scott Weinstein Avatar asked Jun 26 '09 16:06

Scott Weinstein


People also ask

What is MSBuild XML?

The Microsoft Build Engine is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software.

What is MSBuild project file?

The MS Build project file format is used by Visual Studio to store information about projects it manages. Project files can be evaluated (or run) on the command line ( cmd.exe , PowerShell) with MSbuild.exe .

What is a .proj file?

A PROJ file is a project file created in Microsoft Visual Studio, a software development tool used to create Windows programs and web applications. It contains XML-formatted text that defines a project's content, platform requirements, versioning information, and web server or database server settings.


1 Answers

After looking at your comment again I realized that I mis-intrepreted what you really needed. This is an interesting problem you have on your hands.

If you don't mind editing the project file itself you may be able to get pretty close to what you want. There is an item FileWrites that keeps track of all the files that were written out during the build process. To start playing around with this edit the project file to have this AfterBuild target

<Target Name="AfterBuild">
  <Message Text="FileWrites: @(FileWrites)" Importance="high"/>
</Target>

There are some problems with this approach as well

  • You have to edit the project file itself
  • This will contain files written to the intermediate output dir (i.e. obj) and the output dir (i.e. bin)
  • If there are build customizations, they are not required to write to this item

You might think that you could solve the first problem with the MSBuild: Find Many Project References technique and output the FileWrites item after doing a build. This will only work if the wrapper proj file was placed in the same folder as the original project itself because all the items inside of a .csproj file are declared with a relative path. So there goes that for the most part.

You can get over the second limitation by using the FindUnderPath task to only get the files placed in the OutputPath folder.

What you could do but is not really reliable either is to examine the OutputPath at the begining of the build and then once again at the end of the build nad see what was added. Let's say that you put the original files into an item StartFiles and at the end of the build put all the files into an item named EndFiles you could the do:

<Target Name="SomeTargetHere">

<ItemGroup>
    <FilesWritten Include="@(EndFiles)" />
    <FilesWritten Remove="@(StartFiles)"/>
</ItemGroup>

<!-- Now FilesWritten contains the difference between EndFiles & StartFiles -->

</Target>

In short I'm not sure if there is a good solution that doesn't involve either a custom task or a custom logger :(.

Sayed Ibrahim Hashimi

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build

like image 150
Sayed Ibrahim Hashimi Avatar answered Oct 02 '22 01:10

Sayed Ibrahim Hashimi