Search code examples
c#windows-8windows-8.1assetsbuildaction

Setting the Build Action for a folder in VS for a Win 8.1 app


In previous Windows 8 /8.1 projects, any images that I have added to a folder inside the Assets folder is automatically set to "Content" in the Build Action.

Build Action set to Content

As a result, the images render when the project is built.

But our latest project seems to default to BundleResource, and after wasting time trying to work out why the image isn't rendering, I remember that I have to manually change each image to Content.

Does anyone know how to set the whole folder to Content so that newly added images will be Content by default? I don't know why this project is behaving differently to our previous ones. :-(


Solution

  • I had the same issue while ago. As far as I know is not possible to set Build Actions for folders on Visual Studio, only individual files.

    The solution I've found is to edit Project.projitems manually (I mean, outside of VS and after it is closed, via another code editor) from:

    <ItemGroup>
      <Content Include="$(MSBuildThisFileDirectory)Assets\example.json" />
      <Content Include="$(MSBuildThisFileDirectory)Assets\NestedFolder\example.file" />
    </ItemGroup>
    

    to this:

    <ItemGroup>
      <Content Include="$(MSBuildThisFileDirectory)Assets\**\*.*">
    </ItemGroup>
    

    Which will do the trick of setting everything under Assets as Build Action: Content, and will be able to see it mapped on Solution Explorer after restarting VS - or rebuilding files.

    NOTE: Keep in mind that if you add anything to this folder via VS this rule could be overwritten. So, my advice is: once this rule is added, only add files directly to the folder.