Sitecore helix Apply-Xml-Transform 替换整个 web.config 而不是转换

Sitecore helix Apply-Xml-Transform replaces entire web.config instead of transforming

遇到一个问题,当我的 Gulp 任务 运行 是 XML 转换任务时,它会替换 Sitecore 应用程序 web.config 文件的全部内容而不是转换元素.. 不明白为什么?

我在我的解决方案中的不同项目中有 2x web.config.transform 文件,这两个文件都具有 XML-Document-Transform 命名空间,到目前为止它们中的内容很少..示例一个在这里:

<?xml version="1.0" encoding="utf-8"?>

<configuration  xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <runtime xdt:Transform="InsertIfMissing">
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xdt:Transform="InsertIfMissing">
      <dependentAssembly xdt:Transform="InsertIfMissing">
        <assemblyIdentity xdt:Transform="InsertIfMissing" name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect xdt:Transform="InsertIfMissing" oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly xdt:Transform="InsertIfMissing">
        <assemblyIdentity xdt:Transform="InsertIfMissing" name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect xdt:Transform="InsertIfMissing" oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly xdt:Transform="InsertIfMissing">
        <assemblyIdentity xdt:Transform="InsertIfMissing" name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect xdt:Transform="InsertIfMissing" oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
      </dependentAssembly>
      <dependentAssembly xdt:Transform="InsertIfMissing">
        <assemblyIdentity xdt:Transform="InsertIfMissing" name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect xdt:Transform="InsertIfMissing" oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
    </runtime>

<system.codedom xdt:Transform="InsertIfMissing">
<compilers xdt:Transform="InsertIfMissing">
  <compiler xdt:Transform="InsertIfMissing" xdt:Locator="Match(language)" language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
  <compiler xdt:Transform="InsertIfMissing" xdt:Locator="Match(language)" language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>

我的 gulpfile 几乎是标准的 Helix 文件:

gulp.task("04-Apply-Xml-Transform", function () {
var layerPathFilters = ["./src/Foundation/**/*.transform", "./src/Feature/**/*.transform", "./src/Project/**/*.transform", "!./src/**/obj/**/*.transform", "!./src/**/bin/**/*.transform"];
return gulp.src(layerPathFilters)
    .pipe(foreach(function (stream, file) {
        var fileToTransform = file.path.replace(/.+code\(.+)\.transform/, "");
        util.log("Applying configuration transform: " + file.path);
        return gulp.src("./scripts/applytransform.targets")
            .pipe(msbuild({
                targets: ["ApplyTransform"],
                configuration: config.buildConfiguration,
                logCommand: false,
                verbosity: "normal",
                stdout: true,
                errorOnFail: true,
                maxcpucount: 0,
                toolsVersion: config.buildToolsVersion,
                properties: {
                    Platform: config.buildPlatform,
                    WebConfigToTransform: config.websiteRoot,
                    TransformFile: file.path,
                    FileToTransform: fileToTransform
                }
            }));
    }));
});

applytransform.targets文件也是股票螺旋之一:

<Project ToolsVersion="14.0" DefaultTargets="ApplyTransform" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(MSBuildToolsVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="ApplyTransform">
    <ItemGroup>
      <Transform Include="$(TransformFile)" />

      <ConfigsToTransform Include="$(FileToTransform)" Condition="Exists(@(Transform))">
        <TransformPath>%(Transform.Identity)</TransformPath>
      </ConfigsToTransform>
    </ItemGroup>
    <Message Text="@(ConfigsToTransform)"></Message>
    <Message Text="@(Transform)"></Message>

    <TransformXml Source="$(WebConfigToTransform)\%(ConfigsToTransform.Identity)"
              Transform="%(ConfigsToTransform.TransformPath)"
              Destination="$(WebConfigToTransform)\%(ConfigsToTransform.Identity)"
              Condition="Exists(@(Transform))"/>
      </Target>
    </Project>

当我 运行 任务时,输出看起来都很正常,但是我网站根目录中的结果 web.config 文件只包含两个转换文件中的内容,我丢失了所有常规应用程序配置设置..

有人知道怎么回事吗?

原来我的问题有两个方面。

  1. 我没有仔细查看 Sitecore.Foundation.Installer 项目,我认为该项目仅用于安装虚拟 XDB 和报告数据,但实际上它包含一些转换工具的逻辑。
  2. 我在 foundation/feature 层中添加了一些新项目,结果发现默认情况下 web.config 文件当您右键单击 -> 查看属性时有它的 "Build Action' set to " 内容”这导致此文件被放入最终发布到 Web 根目录的输出目录。这应该设置为 'None' 和 'Copy to Output Directory' 设置为“不复制”。