我可以有不同的“.settings”吗?指定用于调试和发布配置?
我有一个 .settings 文件(包含用户和应用程序设置),如果在调试模式下构建,我希望包含不同的值。有支持或推荐的方法来执行此操作吗?
I have a .settings file (containing both User and Application settings) that I would like to contain different values if built in Debug mode. Is there a supported or recommended way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我为每种模式使用两个单独的配置文件。我将文件复制到 POST-BUILD 事件中的 BIN 文件夹中。
I use two separate config files for each mode. I copy the files into the BIN folder in the POST-BUILD event.
Settings.Designer.cs 文件不包含值,仅包含应用程序设置属性声明。这些值是单独存储的。应用程序设置值进入 app.exe.config 文件,用户范围的设置值进入 appdata 文件夹,该文件夹的名称由哈希算法生成。你只会遇到后者的麻烦。没关系,当您将发布版本部署到计算机时,该文件将不存在。
如果您的意思是“我可以更改默认值”,那么答案是:当您使用设置设计器时不能。您必须将设置移至单独的类中。使其看起来与此类似:
确保命名空间名称与 Settings.Designer.cs 文件中使用的名称匹配,并且从“设置”页面中删除该设置。
The Settings.Designer.cs file doesn't contain values, only application setting property declarations. The values are stored separately. Application setting values go into the app.exe.config file, user scoped setting values go in an appdata folder that has a name generated by a hashing algorithm. You'd only have trouble with the latter. Shouldn't matter, the file won't exist when you deploy your Release build to a machine.
In case you mean "can I change the default value" then the answer is: not when you use the settings designer. You'll have to move the setting into a separate class. Make it look similar to this:
Make sure the namespace name matches the one used in the Settings.Designer.cs file and that you delete the setting from the Settings page.