从web.template.xml web.config中变换不工作 [英] web.config transform from web.template.xml not working

查看:200
本文介绍了从web.template.xml web.config中变换不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让web.config文件转换中进行了介绍的这里。我们使用了在其他项目上这个方法,它的工作原理没有问题,但不是在这个新项目。

下面是我已经尝试没有成功测试


  • 在情况下,我得到了项目名称更改错误wpp.targets文件的名称。我知道我使用的作品,因为它导致的web.config从web.template.xml此转换工程重建是唯一一个在当前之一。只有子模板不工作。

  • 试图用XDT:定位器=匹配(名称)

  • 试过的.config扩展VS的.xml,我们的其他项目中这个工程使用的.xml

  • 配置管理器设置为使用测试配置我工作的项目。

  • web.template.Test.xml有XDT:转换=替换因为我想要替换部分

  • web.template.xml有占位符

  • 试过下面链接的堆栈问题的建议去除wpp.targets了CopyWebTemplateConfig部分。我们的其他项目有这个和的PropertyGroup部分注释掉了,我都试过组合。

我已经通过上面的链接多次阅读,这与堆栈<一个href=\"http://stackoverflow.com/questions/3922291/use-visual-studio-web-config-transform-for-debugging\">question,但看不出是什么问题。

注意的发布做变换的方式工作。它创建一个包含从web.template.Test.xml值的web.template.xml文件,但作为wpp.targets指示不创建web.config.xml。因此,这是越来越构建变换工作似乎更成问题的。

任何人有什么遗漏的想法?

wpp.targets

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;项目ToolsVersion =4.0的xmlns =htt​​p://schemas.microsoft.com/developer/msbuild/2003&GT;  &LT;! - 确保web.config文件将在那里甚至包/发布 - &GT;
  &lt;目标名称=CopyWebTemplateConfigBeforeTargets =生成&GT;
    &LT;复制来源档案=web.template.xml
          DestinationFiles =web.config文件/&GT;
  &LT; /目标&GT;  &LT;&的PropertyGroup GT;
    &LT; prepareForRunDependsOn&GT;
      $(prepareForRunDependsOn);
      UpdateWebConfigBeforeRun;
    &LT; / prepareForRunDependsOn&GT;
  &LT; /&的PropertyGroup GT;  &LT;! - 运行在Visual Studio中您的应用程序之前,此目标将正确的运行 - &GT;
  &lt;目标名称=UpdateWebConfigBeforeRun&GT;
    &LT;消息文本=配置:$(配置):$ Web.template(配置)的.xml/&GT;
    &LT;的TransformXML源=web.template.xml
              变换=web.template。$(配置)的.xml
              目标=web.config文件/&GT;
  &LT; /目标&GT;  &LT;! - 排除从创建的软件包的配置模板文件 - &GT;
  &lt;目标名称=ExcludeCustomConfigTransformFilesBeforeTargets =ExcludeFilesFromPackage&GT;
    &LT;&的ItemGroup GT;
      &LT; ExcludeFromPackageFiles包括=web.template.xml; web.template * XML。/&GT;
    &LT; /&的ItemGroup GT;
    &LT;消息文本=ExcludeFromPackageFiles:@(ExcludeFromPackageFiles)重要性=高/&GT;
  &LT; /目标&GT;
&LT; /项目&GT;

web.template.xml

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;! -
  有关如何配置ASP.NET应用程序的更多信息,请访问:
  http://go.microsoft.com/fwlink/?LinkId=152368
   - &GT;
&LT;结构&gt;
  &LT; configSections&GT;
    &LT; sectionGroup NAME =TestSettings&GT;&LT; / sectionGroup&GT;
    ....
  &LT; / configSections&GT;
    ....
  &LT; TestSettings&GT;
  &LT; / TestSettings&GT;
   ....
&LT; /结构&gt;

web.template.Test.xml

 &LT;?XML版本=1.0&GT?;
&LT;! - 有关使用转换的更多信息
     请参阅http://go.microsoft.com/fwlink/?LinkId=214134 web.config中的例子。 - &GT;
&lt;结构的xmlns:XDT =htt​​p://schemas.microsoft.com/XML-Document-Transform&GT;
  &LT; TestSettings XDT:转换=替换&GT;
    ...
  &LT; / TestSettings&GT;
&LT; /结构&gt;

MSBuild的输出

从项目的C

 目标UpdateWebConfigBeforeRun:(目标ID:143)文件\\ ... \\ Project.wpp.targets C:\\ ... \\项目。的csproj(目标prepareForRun依赖于它):
任务消息(TASKID:93)
  配置:测试:Web.template.Test.xml(TASKID:93)
完成执行任务消息。 (TASKID:93)
任务的TransformXML(TASKID:94)
  转化源文件:Web.template.xml(TASKID:94)
    应用转换文件:Web.template.Test.xml(TASKID:94)
    执行替换(改造5号线,18)(TASKID:94)
      上/配置/ TestSettings(TASKID:94)
      适用于TestSettings'元素(源线121,4)(TASKID:94)
      替换成'TestSettings'元素(TASKID:94)
    完成执行替换(TASKID:94)
    输出文件:web.config文件(TASKID:94)
  转型成功(TASKID:94)
完成执行任务的TransformXML。 (的TaskID:94)
项目Project.csproj:完成建设目标UpdateWebConfigBeforeRun(目标ID:143)


解决方案

我有一个解决我的问题,但不知道原因是什么,所以如果这将解决它在其他情况下不能确定。

我回顾了诊断的MSBuild的输出,并注意到对到底有是复制web.template到web.config中的另一个部分。注意,这是后UpdateWebConfigBeforeRun目标已经跑了,并提出从子模板及其更新转换文件web.config中。它看起来像这最后一步是覆盖在web.config的变换,我想。

我不知道在哪里这最后一组复制的指令是从哪里来的,所以我也为寻找其他wpp.target文件在我的电脑上的所有文件进行搜索。我发现了一个又一个在慢猎豹的扩展文件夹,看到一些部分往上顶被设置属性transformOnBuild为假。

思维有一个与SlowCheetah冲突,我卸载它和转换开始工作正常。这仍然是一个有点古怪,因为与SlowCheetah工作的其他解决方案启用。心血来潮我重新装SlowCheetah和改造继续按预期方式工作。

所以,我的解决方案最终被SlowCheetah的重新安装。我仍然感到困惑的是什么这个问题的原因是,如果其他人张贴一个答案我给他们的奖金。

I'm trying to get web.config transformations working as described here. We've used this method on other projects and it works without issue, but not on this new project.

Here's what I've tried testing without success

  • Changing name of wpp.targets file in case I got the project name wrong. I know the current one I'm using works since it's the only one that causes web.config to be rebuilt from web.template.xml this transform works. Only the sub templates don't work.
  • Tried with xdt:Locator="Match(name)"
  • Tried .config extension vs .xml, our other projects where this works use .xml
  • Configuration manager is set to use the "Test" configuration for the project I'm working on.
  • web.template.Test.xml has xdt:Transform="Replace" for the section I want to replace
  • web.template.xml has the placeholder
  • Tried removing the "CopyWebTemplateConfig" section from wpp.targets as suggested on the stack question linked below. Our other projects have this and the "PropertyGroup" section commented out and I've tried both combinations.

I've read through the above link multiple times and this related stack question, but can't see what the problem is.

Note The publish transform does work in a way. It creates a web.template.xml file that contains the values from web.template.Test.xml, but does not create a web.config.xml as the wpp.targets instructs. So this is more of an issue with getting the build transform working it seems.

Anyone have an idea of what's missing?

wpp.targets

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- Make sure web.config will be there even for package/publish -->
  <Target Name="CopyWebTemplateConfig" BeforeTargets="Build">
    <Copy SourceFiles="web.template.xml"
          DestinationFiles="web.config"/>
  </Target>

  <PropertyGroup>
    <PrepareForRunDependsOn>
      $(PrepareForRunDependsOn);
      UpdateWebConfigBeforeRun;
    </PrepareForRunDependsOn>
  </PropertyGroup>

  <!-- This target will run right before you run your app in Visual Studio -->
  <Target Name="UpdateWebConfigBeforeRun">
    <Message Text="Configuration: $(Configuration): Web.template.$(Configuration).xml"/>
    <TransformXml Source="web.template.xml"
              Transform="web.template.$(Configuration).xml"
              Destination="web.config" />
  </Target>

  <!-- Exclude the config template files from the created package -->
  <Target Name="ExcludeCustomConfigTransformFiles" BeforeTargets="ExcludeFilesFromPackage">
    <ItemGroup>
      <ExcludeFromPackageFiles Include="web.template.xml;web.template.*.xml"/>
    </ItemGroup>
    <Message Text="ExcludeFromPackageFiles: @(ExcludeFromPackageFiles)" Importance="high"/>
  </Target>
</Project>

web.template.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <configSections>           
    <sectionGroup name="TestSettings"></sectionGroup>
    ....
  </configSections>
    ....
  <TestSettings>
  </TestSettings>
   ....
</configuration>

web.template.Test.xml

<?xml version="1.0"?>
<!-- For more information on using transformations 
     see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <TestSettings xdt:Transform="Replace">
    ...
  </TestSettings>
</configuration>

MSBuild output

Target "UpdateWebConfigBeforeRun: (TargetId:143)" in file "C:\...\Project.wpp.targets" from project "C:\...\Project.csproj" (target "PrepareForRun" depends on it):
Task "Message" (TaskId:93)
  Configuration: Test: Web.template.Test.xml (TaskId:93)
Done executing task "Message". (TaskId:93)
Task "TransformXml" (TaskId:94)
  Transforming Source File: Web.template.xml (TaskId:94)
    Applying Transform File: Web.template.Test.xml (TaskId:94)
    Executing Replace (transform line 5, 18) (TaskId:94)
      on /configuration/TestSettings (TaskId:94)
      Applying to 'TestSettings' element (source line 121, 4) (TaskId:94)
      Replaced 'TestSettings' element (TaskId:94)
    Done executing Replace (TaskId:94)
    Output File: web.config (TaskId:94)
  Transformation succeeded (TaskId:94)
Done executing task "TransformXml". (TaskId:94)
Done building target "UpdateWebConfigBeforeRun" in project "Project.csproj".: (TargetId:143)

解决方案

I've got a solution to my problem, but not sure what the cause is, so not sure if this will solve it in other cases.

I reviewed the output of the MSBuild diagnostic and noticed that towards the end there was another section that copied web.template to web.config. Note that this is after the UpdateWebConfigBeforeRun target already ran and made its updates from the sub template transform file to web.config. It looked like this last step was overriding the web.config with the transform I wanted.

I wasn't sure where this last set of copy instruction was coming from, so I did a search for all files on my PC looking for other wpp.target files. I found another one in Slow Cheetah's extensions folder and saw some section up top that was setting a property "transformOnBuild" to false.

Thinking there was a conflict with SlowCheetah, I uninstalled it and the transformations started working as expected. This was still a bit odd since the other solutions worked with SlowCheetah enabled. On a whim I re-installed SlowCheetah and the transformation continued to work as expected.

So my solution ended up being a re-installation of SlowCheetah. I'm still confused about what the cause of this issue was, so if anyone else posts an answer to this I'll give them the bounty.

这篇关于从web.template.xml web.config中变换不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆