Search code examples
uwpassetswindows-10-universal

UWP assets marked as 'Content' aren't re-deployed if the app moves/deletes them


I have some (SQLite .db) files in my UWP app's Assets folder, which have their Build Action set to Content in their Properties.

When I build the app, these are deployed to the app, and can be accessed at runtime from the Windows.ApplicationModel.Package.Current.InstalledLocation StorageFolder.

However, I need to move these from this location to another (ApplicationData.Current.LocalFolder) on first launch of the app. They contain initial data, but may be later replaced with new .db files from a server. I move them from this initial location to another so that this only happens on first launch (on further launches, the file is therefore not in the InstalledLocation, so it doesn't overwrite potentially updated files).

If I do this, they are no longer deployed on further builds of the app, even if I uninstall the app. The only way to get them to be re-deployed is to remove them and re-add them to the project.

Is this expected behaviour? If so, perhaps I am approaching this in the wrong way?


Solution

  • My solution to this was to add a pre-build event to 'touch' the files I am moving (.db files).

    In the project's Properties, go to Build Events and add the following as the Pre-build event command line:

    COPY /B $(ProjectDir)Assets\*.db+,, $(ProjectDir)Assets\
    

    Windows doesn't have a touch command, but the above code does essentially that - it updates the modified date of all the .db files in the Assets folder of the project). Thanks!

    Then Visual Studio will think the files have changed and will re-deploy them on each build.