Copy a file only if not present.

Topics: General
Oct 24, 2013 at 10:46 PM
The package I creating now include a required XML file. It is a "starter" file, which the user is expected to customize. As such, when updating or re-installing, I do not want to overwrite an existing file. So, I need to copy the file only when it's not already present.

That sound like such a basic operation, but I cannot see anyway of doing it.

The closest way I've found is to make it an XDT Transform file, with every line having a xdt:Transform="Insert" attribute, but I don't think even that would work, as a large block of it is an XML comment (explaining how to customize the file)

Am I missing something?
Mar 6, 2015 at 9:05 PM
I am trying to do the same. Did you ever figure it out?
Mar 6, 2015 at 10:30 PM
Well, what I did was to create two packages -- one with the assembly and one with the readme & config file. The latter depends on the former, with the recommendation that you download the latter. Then I can just update the one with just the assembly.

However, it appears that if an update tries to overwrite a file that you have customized, NuGet will warn you, so it's probably not an issue at all.
Mar 6, 2015 at 11:26 PM
Thanks for the info. There is a dialog that pops up asking if the file should be overwritten, however I want to suppress this dialog because I only want to copy the file if it is not there. The user customizes the file, and it would be bad if they accidentally overwrote it.