Search code examples
c#web-config-transform

Include a file in a csproj but exclude it from publishing?


We use a local config file with database connection strings, in the event we need to hook our local computer up to the development or even production database. We call this file ConnectionStrings.local.config and it's included in our C# project so we can edit it easily.

I don't want this file to be included when I go to the publish web tool, since we are going to use config transforms that will swap out the connection strings property for the real data source on each server.

I modified my .csproj file as follows:

Exclude

but the ConnectionStrings.local.config file still shows up in the folder after being published.

How can I remove it from deployment without excluding the file from Visual Studio?


Solution

  • In the property window of the given file (from Visual Studio), set "Copy to Output Directory" to "Do Not Copy", and be sure "Build Action" is "None."

    Also, did you clear out your DESTINATION directory first? Perhaps the file was left there from your previous publish? By default, publishing will not "clean" the destination directory.