C# VS.NET 2008 更改每个配置的设置
有没有办法为每个构建配置提供不同的应用程序设置?
我希望能够使用不同的设置批量构建一些配置,而不必更改设置并构建、冲洗重复。
提前致谢!
Is there a way to have different application settings per each build configuration?
I would like to be able to batch build a few configurations with different settings, instead of having to change the settings and build, rinse repeat.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我对 appsettings 架构了解不多(我从未真正使用过它),但您可以使用一些 MSBuild 魔法为常量定义不同的值。
创建两个 .cs 文件,Constants1.cs 和 Constants2.cs(或根据您的配置命名它们)。
在每个文件中,定义一个名为 Constants 的类(或其他名称)——但要像每个文件都是唯一的定义一样(即使用相同的类名)。 通常,这应该只定义
public static readonly
字段——不要使用const
,因为这可能会给您带来部分构建的麻烦。现在卸载您的项目文件并编辑它。 找到如下所示的条目:
并像这样更改它们:
最后保存并重新加载您的项目。 现在,一次实际上只会构建一个文件,具体取决于您的构建配置。
I don't know much about the appsettings architecture (I've never really used it), but you can define different values for constants using a bit of MSBuild magic.
Create two .cs files, Constants1.cs and Constants2.cs (or name them after your configurations).
In each file, define a class called Constants (or whatever) -- but do it as if each file were the only definition (ie. use the same class name). Typically, this should just define
public static readonly
fields -- do not useconst
, as that can get you into trouble with partial builds.Now Unload your project file and Edit it. Find the entries that look like this:
and change them like so:
Finally Save and Reload your project. Now only one of the files will actually be built at a time, depending on your build configuration.
您可以向项目添加预构建或构建后任务,您可以从那里访问 ConfigurationName。 执行“copy Web.config.debug Web.config”之类的操作相当容易
You could add a prebuild or postbuild task to the proj, you have access to the ConfigurationName from there. Would be fairly easy to do something like "copy Web.config.debug Web.config"
除此之外,MS还承诺在VS 2010中添加这个功能。
Besides all these, MS promised to add this feature in VS 2010.
“应用程序设置”下是什么意思? 每个配置(例如调试或发布)的项目属性? 或者每个都需要 defirent app.conf 文件?
如果首先,您可以使用合适的设置创建多个配置,然后使用批量构建来依次构建它们。
http://msdn.microsoft.com/en-us/library/169az28z。 aspx
或如 Google Ninja 所说,使用预构建任务:
删除 Web.config 应用程序.config
复制 Web.config.调试 Web.config
(在它之前创建一些配置文件)
What do you mean under 'application settings' ? Project's property for each configuration such as Debug or Release? Or defirent app.conf file for each of them?
If first, you can create a number of configurations with suitable settings and use Batch Build to build them by turn.
http://msdn.microsoft.com/en-us/library/169az28z.aspx
or as Google Ninja said, use pre-build task:
del Web.config app.config
copy Web.config.Debug Web.config
(create a number of configuration files before it)