App.config only for my developer machine

我怕爱的太早我们不能终老 提交于 2019-12-24 08:27:41

问题


Can I create app.config or web.config file that applies only to my developer machine, as opposed to using the default configuration files that are checked into source control?


回答1:


You can have an app.config for each environment, if is this what you are looking for. Try this: http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx




回答2:


I would recomend using separate config files that are referred to by your app.config or web.config.

For example in your web.config you would have:

<configuration>
    <appSettings file="Config/LocalDev.config">
    </appSettings>
</configuration>

And then in Config/LocalDev.config you would have

<appSettings>
    <add key="SomeKey" value="SomeValue"/>
    <add key="AnotherKey" value="AnotherValue"/>
</appSettings>

You would also create a Config/Production.config file with your production settings. Then all you have to do is edit the appSettings file in your web.config when you deploy.




回答3:


To do this, you need to exclude web.config or app.config from source control.




回答4:


What I would recommend doing is checking in an "app.config.backup" file whilst ignoring all app.configs. This will allow you to modify your own app.config accordingly without interfering with other developer's machines, whilst at the same time allowing for updates to the existing "base" configuration.




回答5:


Depending on what exactly you are trying to achieve, you may find Machine.config helpful.




回答6:


Use a copy of web.config named web.svn.config to be under source control.

That way, the source-controlled config file (web.svn.config) contains all required settings, and each developer can maintain their own config files (web.config) on their dev machines.




回答7:


If you want configuration that applies only to your machine and each developer will likely be doing the same thing then you can do as we do and have only a minimum configuration in the web.config that is part of the solution and the rest in your global web.config or machine.config (if you need to also have some desktop apps use it). We do this to create an isolated environment between dev/qa/staging/prod and it is still easy to push from one environment to the next without having to edit the config files or worry about overwriting them. We also further isolate our environments by include host file entries that only allow machines in dev communicate with others at the same level. Likewise for qa/staging/prod.



来源:https://stackoverflow.com/questions/2309178/app-config-only-for-my-developer-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!