问题:
DataFolder.config
文件未恢复为以前的状态(patch
元素的值)。此外,没有任何自定义配置文件转换被推送到目标文件夹。
有趣的是ConnectionStrings.config
文件在转换后被转换回原始状态,而不是DataFolder.config
。
<Target Name="BeforeBuild">
<!-- Web.config, ConnectionStrings.config, DataFolder.config
Duplicates original config files into a temp file -->
<Copy SourceFiles="Web.config" DestinationFiles="Web.temp.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(ProjectDir)\App_Config\Include\zzz\DataFolder.config" DestinationFiles="$(ProjectDir)\App_Config\Include\zzz\DataFolder.temp.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(ProjectDir)\App_Config\ConnectionStrings.config" DestinationFiles="$(ProjectDir)\App_Config\ConnectionStrings.temp.config" OverwriteReadOnlyFiles="True" />
<!-- Tranforms config files -->
<TransformXml Source="Web.temp.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
<TransformXml Source="$(ProjectDir)\App_Config\Include\zzz\DataFolder.temp.config" Transform="$(ProjectDir)\App_Config\Include\zzz\DataFolder.$(Configuration).config" Destination="$(ProjectDir)\App_Config\Include\zzz\DataFolder.config" />
<TransformXml Source="$(ProjectDir)\App_Config\ConnectionStrings.temp.config" Transform="$(ProjectDir)\App_Config\ConnectionStrings.$(Configuration).config" Destination="$(ProjectDir)\App_Config\ConnectionStrings.config" />
</Target>
<Target Name="AfterPublish123" AfterTargets="MSDeployPublish">
<!-- Overwrite transformed config files with the temps.
Delete temp files for Web.config, ConnectionStrings.config, DataFolder.config -->
<Copy SourceFiles="Web.temp.config" DestinationFiles="Web.config" OverwriteReadOnlyFiles="True" />
<Delete Files="Web.temp.config" />
<Copy SourceFiles="$(ProjectDir)\App_Config\Include\zzz\DataFolder.temp.config" DestinationFiles="$(ProjectDir)\App_Config\Include\zzz\DataFolder.config" OverwriteReadOnlyFiles="True" />
<Delete Files="$(ProjectDir)\App_Config\Include\zzz\DataFolder.temp.config" />
<Copy SourceFiles="$(ProjectDir)\App_Config\ConnectionStrings.temp.config" DestinationFiles="$(ProjectDir)\App_Config\ConnectionStrings.config" OverwriteReadOnlyFiles="True" />
<Delete Files="$(ProjectDir)\App_Config\ConnectionStrings.temp.config" />
</Target>
DataFolder.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<sc.variable name="dataFolder">
<patch:attribute name="value">#{sitecore.DataFolder}</patch:attribute>
</sc.variable>
</sitecore>
</configuration>
DataFolder.Release.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<sc.variable name="dataFolder" xdt:Locator="Match(name)" xdt:Transform="Replace">
<patch:attribute name="value">c:\inetpub\wwwroot\fb822\Data</patch:attribute>
</sc.variable>
</sitecore>
</configuration>
发布完成后,DataFolder.config
的{{1}}元素现在具有patch
元素值的值,但不应该这样。
答案 0 :(得分:0)
问题是AfterPublish
不是一个有效的任务。运行&#34;发布后的正确任务&#34;是:
<Target Name="CustomPostPublishActions" AfterTargets="GatherAllFilesToPublish">
请注意,Name
属性并不重要,它可以是任何内容。这是完成的输出:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="BeforeBuild">
<!-- Web.config, ConnectionStrings.config, DataFolder.config
Duplicates original config files into a temp file -->
<Copy SourceFiles="Web.config" DestinationFiles="Web.temp.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.temp.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.temp.config" OverwriteReadOnlyFiles="True" />
<!-- Tranforms config files -->
<TransformXml Source="Web.temp.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
<TransformXml Source="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.temp.config" Transform="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.$(Configuration).config" Destination="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.config" />
<TransformXml Source="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.temp.config" Transform="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.$(Configuration).config" Destination="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.config" />
</Target>
<Target Name="CustomPostPublishActions" AfterTargets="GatherAllFilesToPublish">
<!-- Overwrite transformed config files with the temps.
Delete temp files for Web.config, ConnectionStrings.config, DataFolder.config -->
<Copy SourceFiles="Web.temp.config" DestinationFiles="Web.config" OverwriteReadOnlyFiles="True" />
<Delete Files="Web.temp.config" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.temp.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.config" OverwriteReadOnlyFiles="True" />
<Delete Files="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.temp.config" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.temp.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.config" OverwriteReadOnlyFiles="True" />
<Delete Files="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.temp.config" />
</Target>
修改强>
添加我的问题,当其他开发人员&#34;建立&#34;该项目并没有发布它,转换文件会改变原始配置,这不是理想的方法。因此,由于我们将File Deploy
用作One-Click Publish
,因此名为Target
的sa CopyAllFilesToSingleFolderForPackage
在文件被推送到目录之前被调用
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="CustomPrePublishActions" BeforeTargets="CopyAllFilesToSingleFolderForPackage">
<!-- Duplicates original config files into a temp file -->
<Copy SourceFiles="Web.config" DestinationFiles="Web.temp.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.temp.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.temp.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.CDN.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.CDN.temp.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.SiteDefintion.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.SiteDefintion.temp.config" OverwriteReadOnlyFiles="True" />
<!-- Tranforms config files -->
<TransformXml Source="Web.temp.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
<TransformXml Source="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.temp.config" Transform="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.$(Configuration).config" Destination="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.config" />
<TransformXml Source="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.temp.config" Transform="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.$(Configuration).config" Destination="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.config" />
<TransformXml Source="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.CDN.temp.config" Transform="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.CDN.$(Configuration).config" Destination="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.CDN.config" />
<TransformXml Source="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.SiteDefintion.temp.config" Transform="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.SiteDefintion.$(Configuration).config" Destination="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.SiteDefintion.config" />
</Target>
<Target Name="CustomPostPublishActions" AfterTargets="GatherAllFilesToPublish">
<!-- Overwrite transformed config files with the temps. -->
<Copy SourceFiles="Web.temp.config" DestinationFiles="Web.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.temp.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.temp.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.CDN.temp.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.CDN.config" OverwriteReadOnlyFiles="True" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.SiteDefintion.temp.config" DestinationFiles="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.SiteDefintion.config" OverwriteReadOnlyFiles="True" />
<!-- Delete temp files -->
<Delete Files="Web.temp.config" />
<Delete Files="$(MSBuildProjectDirectory)\App_Config\Include\zzz\DataFolder.temp.config" />
<Delete Files="$(MSBuildProjectDirectory)\App_Config\ConnectionStrings.temp.config" />
<Delete Files="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.CDN.temp.config" />
<Delete Files="$(MSBuildProjectDirectory)\App_Config\Include\zzzSites\Cinnabon\Cinnabon.SiteDefintion.temp.config" />
</Target>