Friday, June 24, 2011

Impress your colleagues with your knowledge about… Visual Studio wildcards support

Last week I discovered a useful feature in Visual Studio when you have lots of resources. It’s possible to use wildcards to include files in a project. Imagine you have a lot of files you want to add to your project, you can add them all manually or  you can edit the project file once to pick up all of the files and never worry about it again.

How do you this?

  • Right click on the project in Visual Studio and choose ‘Unload Project’.
  • Right click on the unloaded project and choose ‘Edit Project’
  • Add an <ItemGroup/> block with the following:
<ItemGroup> 
<Content Include="Content\Images\*.png"> 
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 
</Content> 
</ItemGroup>
  • Save and reload the project.  All files will be self-included.

I know that by clicking “Show all” and selecting the files you want to add you get the same behaviour, but it’s still neat. Smile

No comments: