I always use a combination of .hgignore and BeforeBuild
(in the .csproj file) for things like this.
In one of my pet projects, I have the following setup:
App.config
contains my real hardcoded user id and password for testing.
App.config.example
is identical, but with fake data like “dummy_user” and “dummy_pw”.
App.config
is not part of the repository, and it’s ignored (in .hgignore
).
App.config.example
is part of the repository.
Then, I have the following in the BeforeBuild
target in the .csproj file of my solution:
<Target Name="BeforeBuild">
<Copy
Condition="!Exists('App.config')"
SourceFiles="App.config.example"
DestinationFiles="App.config"/>
</Target>
All this together has the following effect:
- the config file with the real data can never be accidentally committed to the repository, because it’s ignored
- the repository only contains the config file with the example data
- if someone else clones the repository to his machine, he won’t have the “real” config file…but if it’s missing, it will be automatically created before the first build by Visual Studio / MSBuild by simply copying the
.example
file (and then he can just put his real login data into the newly createdApp.config
file). - if an
App.config
with real hardcoded user data already exists, it won’t be overwritten when building because the BeforeBuild event will only happen ifApp.config
does not already exist