简体   繁体   中英

Change 'Build Action' property for all images in a project in Visual Studio?

I'm wondering if there is a way to update a property for all images in my Visual Studio project?

I have multiple nested folders of images, and I'd like to change their 'Build Action' property from 'Resource' to 'Content'.

Currently I can only highlight and select/change all images in one folder. This is very time consuming when I have hundreds of folders and thousands of images.

I'm using Visual Studio 2013 Professional.

You can leverage wildcard in project file.

  1. Remove all images from your project. If they are in under the same root folder, it would be easy.
  2. Open your .csproj in notepad or VS (tip: Productivity Power Tool makes it extremely easy).
  3. Add a item group

     <ItemGroup> <Content Include="images/**/*.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> 

    Note ** is used to include folders recursively. It will include all png files under project file with BuildAction = Content.

After a bit more research, I found a way to edit the project file in the editor. Here are the steps I took to do this:

  1. Right-click on project, select 'Unload Project'. The project name should now be displayed with 'unavailable' displayed next to it.
  2. Right-click on project and choose 'Edit ProjectName.csproj' from the menu. The project XML will now be displayed in the editor.
  3. Use the search and replace functionality (Ctrl+H) to update 'Resource' to 'Content' for all desired images.
  4. Right-click on the project and select 'Reload Project'

This was pretty quick and didn't require creating an additional project to do it programmatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM