我已经使用 Visual Studios 2010 中的“构建部署包”(简称 BDP)几个月了。它工作得很好并且满足了我们想要的基本要求。
我决定更进一步,弄清楚如何获取自定义配置,以便可以在 BDP 生成的 Project.SetParameters.xml 文件中对其进行修改。我们使用它的方式是构建此部署包,并将其交付到客户服务器。每个服务器可能会有所不同,因此我们将 SetParameters.xml 保留在服务器上,只需替换 zip 文件以供以后升级。我们使用 WebDeploy 工具通过构建部署包创建的提供的 cmd 文件来部署它。
我开始研究这个转换网络配置,这非常酷,但我认为我还没有完全理解它。我可以让它执行 web.config 中正常的项目(例如连接字符串、Web 服务器设置等),但是我一生都无法让它为属于其他 DLL 的配置节生成参数包含在 web.config 中。例如:
例如。假设这是一个引用了其他几个程序集的 Web 项目的 web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="SomeAssembly.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<SomeAssembly.Properties.Settings>
<setting name="ExportLocation" serializeAs="String">
<value>C:\MediaExports\</value>
</setting>
</SomeAssembly.Properties.Settings>
</applicationSettings>
</configuration>
我的变压器是:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="SomeAssembly.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<SomeAssembly.Properties.Settings>
<setting name="ExportLocation" value="[MakeMeSetParameter.xml-Entry]" serializeAs="String" xdt:Transform="SetAttributes" xdt:Locator="Match(value)"/>
</SomeAssembly.Properties.Settings>
</configuration>
示例project.xml(不是来自上面的,而是为我的项目生成的):
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<setParameter name="IIS Web Application Name" value="SomeIISNameHere" />
<setParameter name="SomeAssemblySetting-SomeDescriptionOddPlaceforit" value="TheValueToBePlaced" />
<setParameter name="SomeGeneratedValueIwant" value="TheNewMediaExportLocation"/>
</parameters>
我不知道要在变压器 web.config 中放入什么以使其生成 Project.SetParameters.xml 的输出。 “标记化”参数。
现在,我知道我并没有完全理解这一点,但我似乎找不到任何人们对项目引用的其他程序集使用自定义配置的示例。几乎所有示例似乎都与连接字符串和其他常见的 web.config 项有关。
我能找到的最接近我想做的事情是http://sedodream.com/2010/11/11/ASPNETWebApplicationPublishPackageTokenizingParameters.aspx但是它又只是关于连接字符串,而不是我想要的其他程序集的自定义设置参数放。我想为 web.config 中的任何内容创建这些令牌。
我们如何配置转换器配置文件,以便 BDP 可以生成 SetParameters.xml,其中包含用于 web.config 中自定义配置的附加 setParameter 节点?