8

I was adding a folder to my visual studio 2008 project, by dragging and dropping from explorer. I want to change the 'copy to output directory' property of the entire files in that folder to 'Copy Always'.

The problem is that the folder contains many subfolders, and so does the subfolders..so it was a little bit annoying not to be able to block all files and change the property in one step.

Is there a way to change the property of all the files in a folder containing many subfolders in one procedure?

Many Thanks...

wong chung yie
  • 175
  • 1
  • 4
  • 14
  • 1
    I'm sure you could have a neat little powershell script to update the csproj file if you wanted. :D – Russell Nov 24 '11 at 04:18

3 Answers3

7

Just expand all the folders. Select all the files at once, and change the Build Action to "Copy Always". You can select the top item, hold shift, select the last item and that will select all items.

Paul Alexander
  • 31,970
  • 14
  • 96
  • 151
  • As the OP stated, when the files are across multiple folders, you cannot do this. – Valamas Nov 24 '11 at 03:49
  • 1
    Sure it does, I do this all the time. – Paul Alexander Nov 24 '11 at 03:51
  • Using this method, only the `File Name` property is present. – Valamas Nov 24 '11 at 03:59
  • Thank You for the response, Paul. I can select all the files..just like you said, but when i moved to the 'properties window', it seems that Valamas was right. Can you show me where the 'Build Action' you mention earlier? oh, one more thing..does anyone know the easy way to expand all the subfolder? ( Sorry for my stupid questions :D) – wong chung yie Nov 24 '11 at 04:07
  • 1
    @wongchungyie, you need to exclude folder names from the selection to get the Build Action in properties window. You can first select all using shift and then exclude by pressing ctrl key and clicking on folders! – VinayC Nov 24 '11 at 04:25
  • @VinayC, Actually..you were right! I still search for a better solution, since my project contain many subfolders with different depth. But Paul suggestion does helps a lot. many Thanks – wong chung yie Nov 24 '11 at 04:43
  • Late to the party, but this does work - you just need to use CTRL + click to select *the files only*: http://i.imgur.com/rKDZ7Bh.png. Then right click and select the Build Action you require. – Rory McCrossan Mar 06 '17 at 09:44
  • Beware Visual Studio can freeze for a long time when you do this. – Pablo Recalde Jan 13 '20 at 12:00
3

If you really have a lot of sub-folder & files then you can try these steps

  1. Create am empty project, add your folder to the project
  2. Save the project and open the project file in a good text editor
  3. This project file will now have all files for which you want to change the build action
  4. Remove all other tags other than content tags (these refer to your files)
  5. Do simple find & replace to replace //>/n (slash & angled bracket followed by new line) with ">/n<CopyToOutputDirectory>Always<//CopyToOutputDirectory>/n<//Content>". (note that I use notepad++ and hence have escaped slashes). You can always leave out new lines if your tool doesn't support it. You may even try regex find & replace if your tool supports it.
  6. You may have to adjust file path (if your new project has different folder hierarchy) - this can be achieved by find & replace Include=".
  7. Paste these content nodes into the project file that you want to modify
VinayC
  • 47,395
  • 5
  • 59
  • 72
  • I did tried all the solution suggested, and i conclude that the best way is depends on the situation itself. If you have many subfolder with a simple structure then Paul's suggestion is quick,simple and applicable. But, if the depth of the subfolders vary, i will choose Valamas's or VinayC's idea. I choose this as answer for its detail steps. Thank you for all the responses :) – wong chung yie Dec 15 '11 at 02:50
1

Only way I know is to edit the csproj file. You could create a utility to help you do this.

A quick test i did yielded the following.

<Content Include="Test.css" />

After changing the properties...

<Content Include="Test.css">
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Valamas
  • 24,169
  • 25
  • 107
  • 177