默认情况下,管理转换的目标 ( TransformWebConfig
) 仅适用于web.config
文件。
要使其适用于您的appSettings.config
文件,您必须:
- 将
Build Action
文件设置为Content
TransformWebConfig
使用ProjectConfigFileName=appSettings.config
和调用 MSBuild 目标Configuration=$(Configuration)
。
要在文件转换后调用 MSBuildTransformWebConfig
目标,您需要在项目文件的末尾添加:appSettings.config
web.config
<PropertyGroup>
<!-- Name of your custom config file -->
<ConfigFileName>appSettings.config</ConfigFileName>
</PropertyGroup>
<PropertyGroup>
<!--
This property is used to handle circular dependency between
TransformWebConfig and our custom target TransformAppConfig
-->
<FirstRun Condition="$(FirstRun) == ''">true</FirstRun>
</PropertyGroup>
<!-- This target will be called one time after a call to TransformWebConfig -->
<Target Name="TransformAppConfig"
AfterTargets="TransformWebConfig"
Condition="$(FirstRun) == 'true'">
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="TransformWebConfig"
Properties="ProjectConfigFileName=$(ConfigFileName);
Configuration=$(Configuration);
FirstRun=false"/>
</Target>
<!--
This target will be called one time before PreAutoParameterizationWebConfigConnectionStrings
to add $(ConfigFileName) to autoparameterization step
-->
<Target Name="AddToAutoParameterizationStep"
BeforeTargets="PreAutoParameterizationWebConfigConnectionStrings">
<ItemGroup>
<_WebConfigsToAutoParmeterizeCS Include="@(FilesForPackagingFromProject)"
Condition="('%(FilesForPackagingFromProject.Filename)%(FilesForPackagingFromProject.Extension)'=='$(ConfigFileName)') And !%(FilesForPackagingFromProject.Exclude)">
<TransformOriginalFile>$(AutoParameterizationWebConfigConnectionStringsLocation)\original\%(DestinationRelativePath)</TransformOriginalFile>
<TransformOutputFile>$(AutoParameterizationWebConfigConnectionStringsLocation)\transformed\%(DestinationRelativePath)</TransformOutputFile>
<TransformScope>$(_PackageTempDir)\%(DestinationRelativePath)</TransformScope>
</_WebConfigsToAutoParmeterizeCS>
<_WebConfigsToAutoParmeterizeCSOuputFiles Include="@(_WebConfigsToAutoParmeterizeCS->'%(TransformOutputFile)')">
</_WebConfigsToAutoParmeterizeCSOuputFiles>
</ItemGroup>
</Target>