使用Web部署参数时,请使用web.config中的默认值

时间:2022-09-05 20:20:07

I am trying to improve the development and deployment experience in our company by trying to limit the overhead in using multiple environments. We currently have 3 environments: Debug, Test, Release. This means I have multiple configuration files: web.Debug.config, web.Test.config, web.Release.config.

我试图通过尝试限制使用多个环境的开销来改善我们公司的开发和部署体验。我们目前有3个环境:Debug,Test,Release。这意味着我有多个配置文件:web.Debug.config,web.Test.config,web.Release.config。

We are using NuGet packages to deploy the internally developed libraries. The library itself is responsible for the configuration values it uses. This is easily done with NuGet transformation files. Thus, when adding a package to a project, the correct environment transformation file is applied to the correct .config file. Using SlowCheetah and some manual modifications to the csproj file, this works quite well. When switching the build configuration during development, the correct .config file is used; when creating a deployment package it also uses the correct .config file.

我们正在使用NuGet包来部署内部开发的库。库本身负责它使用的配置值。使用NuGet转换文件可以轻松完成此操作。因此,在向项目添加包时,会将正确的环境转换文件应用于正确的.config文件。使用SlowCheetah和对csproj文件的一些手动修改,这非常有效。在开发期间切换构建配置时,使用正确的.config文件;在创建部署包时,它还使用正确的.config文件。

The problem arises when I want to use a parameters.xml file to allow the release manager to change the configuration values when deploying. (How to: Use Web Deploy Parameters in a Web Deployment Package) He sometimes wants to set up a separate environment to do be able to test certain things, whilst not disturbing the existing test environment.

当我想使用parameters.xml文件允许发布管理器在部署时更改配置值时,会出现问题。 (如何:在Web部署包中使用Web部署参数)他有时希望设置一个单独的环境来测试某些事情,同时不会干扰现有的测试环境。

In theory, the use of a parameters file is the perfect solution. In reality it seems the parameters file is not capable of using the configuration values from the corresponding configuration file when no values are passed. This means that, when we provide a parameters file, we must define the actual default values for each possible replacement value. And of course, this complicates things as their is only one parameters file for all configurations. Always specifying every configuration value when deploying is also not preferred, because this means that, when a configuration value changes, we must change it in two places: the NuGet package and the deployment script which deploys to the default environments.

理论上,使用参数文件是完美的解决方案。实际上,当没有传递任何值时,参数文件似乎无法使用相应配置文件中的配置值。这意味着,当我们提供参数文件时,我们必须为每个可能的替换值定义实际的默认值。当然,这使事情变得复杂,因为它们只是所有配置的一个参数文件。始终在部署时指定每个配置值也不是首选,因为这意味着,当配置值发生更改时,我们必须在两个位置更改它:NuGet包和部署到默认环境的部署脚本。

What would be the easiest way to solve our problem? How can we tell the web deploy wizard to use the default values from the .config file generated when creating the deployment package if no value is filled in?

什么是解决我们问题的最简单方法?如果没有填写任何值,我们如何告诉Web部署向导使用创建部署包时生成的.config文件中的默认值?

1 个解决方案

#1


0  

I have been struggling with this issue as well, The best solution I can come up with is to add parameters via the .pubxml files for each deployment, this means a duplication of efforts unfortunately(Surely someone has a better approach?)

我一直在努力解决这个问题,我能想到的最好的解决方案是通过.pubxml文件为每个部署添加参数,这意味着重复工作不幸(当然有人有更好的方法吗?)

#1


0  

I have been struggling with this issue as well, The best solution I can come up with is to add parameters via the .pubxml files for each deployment, this means a duplication of efforts unfortunately(Surely someone has a better approach?)

我一直在努力解决这个问题,我能想到的最好的解决方案是通过.pubxml文件为每个部署添加参数,这意味着重复工作不幸(当然有人有更好的方法吗?)