C# VS.NET 2008 更改每个配置的设置

发布于 2024-07-10 06:28:01 字数 95 浏览 9 评论 0原文

有没有办法为每个构建配置提供不同的应用程序设置?

我希望能够使用不同的设置批量构建一些配置,而不必更改设置并构建、冲洗重复。

提前致谢!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小傻瓜 2024-07-17 06:28:01

我对 appsettings 架构了解不多(我从未真正使用过它),但您可以使用一些 MSBuild 魔法为常量定义不同的值。

创建两个 .cs 文件,Constants1.cs 和 Constants2.cs(或根据您的配置命名它们)。

在每个文件中,定义一个名为 Constants 的类(或其他名称)——但要像每个文件都是唯一的定义一样(即使用相同的类名)。 通常,这应该只定义public static readonly字段——不要使用const,因为这可能会给您带来部分构建的麻烦。

现在卸载您的项目文件并编辑它。 找到如下所示的条目:

    <Compile Include="Constants1.cs" />
    <Compile Include="Constants2.cs" />

并像这样更改它们:

    <Compile Include="Constants1.cs" Condition="'$(Configuration)'=='Debug'" />
    <Compile Include="Constants2.cs" Condition="'$(Configuration)'=='Release'" />

最后保存并重新加载您的项目。 现在,一次实际上只会构建一个文件,具体取决于您的构建配置。

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 use const, 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:

    <Compile Include="Constants1.cs" />
    <Compile Include="Constants2.cs" />

and change them like so:

    <Compile Include="Constants1.cs" Condition="'$(Configuration)'=='Debug'" />
    <Compile Include="Constants2.cs" Condition="'$(Configuration)'=='Release'" />

Finally Save and Reload your project. Now only one of the files will actually be built at a time, depending on your build configuration.

柠檬色的秋千 2024-07-17 06:28:01

您可以向项目添加预构建或构建后任务,您可以从那里访问 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"

帅气尐潴 2024-07-17 06:28:01

除此之外,MS还承诺在VS 2010中添加这个功能。

Besides all these, MS promised to add this feature in VS 2010.

只为一人 2024-07-17 06:28:01

“应用程序设置”下是什么意思? 每个配置(例如调试或发布)的项目属性? 或者每个都需要 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文