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.
我正在尝试按照此处所述进行web.config转换。我们已经在其他项目中使用了这种方法,它没有问题,但在这个新项目上没有。
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.
在我得到项目名称错误的情况下更改wpp.targets文件的名称。我知道我正在使用的当前工作,因为它是唯一一个导致从web.template.xml重建web.config的转换工作。只有子模板不起作用。
尝试使用xdt:Locator =“Match(name)”
尝试.config扩展与.xml,我们的其他项目使用.xml
配置管理器设置为我正在使用的项目使用“测试”配置。
web.template.Test.xml对我要替换的部分有xdt:Transform =“Replace”
web.template.xml具有占位符
尝试从wpp.targets中删除“CopyWebTemplateConfig”部分,如下面链接的堆栈问题所示。我们的其他项目有这个和“PropertyGroup”部分注释掉,我尝试了两种组合。
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.
注意发布转换确实有效。它创建一个web.template.xml文件,其中包含来自web.template.Test.xml的值,但不会像wpp.targets指示的那样创建web.config.xml。所以这似乎是让构建转换正常工作的问题。
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)
5 个解决方案
#1
3
I had installed StyleCop
and that was doing the overwrite for me.
我已经安装了StyleCop,而且正在为我做覆盖。
So I uninstalled it and the issue was resolved.
所以我卸载了它,问题得到了解决。
Funny is that I re-installed the StyleCop
and the transform was still working!
有趣的是我重新安装了StyleCop并且转换仍然有效!
Also at some points I noticed that I should remove the CopyWebTemplateConfig
target section as well.
另外在某些方面我注意到我也应该删除CopyWebTemplateConfig目标部分。
#2
1
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.
我查看了MSBuild诊断的输出,并注意到最后还有另一个部分将web.template复制到web.config。请注意,这是在UpdateWebConfigBeforeRun目标已经运行并将其从子模板转换文件更新到web.config之后。看起来这最后一步是用我想要的转换来覆盖web.config。
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.
我不确定最后一组复制指令的来源,所以我搜索了我的电脑上寻找其他wpp.target文件的所有文件。我在Slow Cheetah的扩展文件夹中找到了另一个,并看到一些顶部将一个属性“transformOnBuild”设置为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.
认为与SlowCheetah存在冲突,我将其卸载并且转换开始按预期工作。由于启用了SlowCheetah的其他解决方案,这仍然有点奇怪。一时兴起,我重新安装了SlowCheetah,转换继续按预期工作。
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.
所以我的解决方案最终是重新安装SlowCheetah。我仍然对这个问题的原因感到困惑,所以如果有人发布了这个问题的答案,我会给他们赏金。
#3
0
I've had a similar issue last week. Turns out that whenever you add a project to a solution in VS 2010 the right project configuration doesn't get applied all the time. So you think you have a configuration active but another is actually active on that project, thus the transformation you expect doesn't get applied.
我上周遇到了类似的问题。事实证明,无论何时将项目添加到VS 2010中的解决方案,都不会始终应用正确的项目配置。因此,您认为您的配置处于活动状态,但另一个配置实际上在该项目上处于活动状态,因此您预期的转换不会得到应用。
Check the steps in last comment of this issue: Custom solution configuration not showing up in Visual Studio 2010
检查此问题的最后评论中的步骤:自定义解决方案配置未显示在Visual Studio 2010中
#4
0
"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."
“我知道我正在使用的当前工作,因为它是唯一导致从web.template.xml重建web.config的工具,这种转换有效。只有子模板不起作用。”
Does this mean, transformation works but TestSettings section alone does not get transformed?
这是否意味着,转换是有效的,但单独的TestSettings部分不会被转换?
Can you share build output with msbuild with verbosity set to diagnostic / detailed?
你可以与msbuild共享构建输出,并将详细程度设置为诊断/详细吗?
#5
0
I wrote a blog post about this subject. I use it everyday in our web application. I wrote the blog post because the feature in slowcheetah isn't ready yet. http://www.locktar.nl/general/use-config-transforms-when-debugging-your-web-application/
我写了一篇关于这个主题的博客文章。我每天都在网络应用程序中使用它。我写博客文章是因为slowcheetah中的功能尚未准备就绪。 http://www.locktar.nl/general/use-config-transforms-when-debugging-your-web-application/
#1
3
I had installed StyleCop
and that was doing the overwrite for me.
我已经安装了StyleCop,而且正在为我做覆盖。
So I uninstalled it and the issue was resolved.
所以我卸载了它,问题得到了解决。
Funny is that I re-installed the StyleCop
and the transform was still working!
有趣的是我重新安装了StyleCop并且转换仍然有效!
Also at some points I noticed that I should remove the CopyWebTemplateConfig
target section as well.
另外在某些方面我注意到我也应该删除CopyWebTemplateConfig目标部分。
#2
1
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.
我查看了MSBuild诊断的输出,并注意到最后还有另一个部分将web.template复制到web.config。请注意,这是在UpdateWebConfigBeforeRun目标已经运行并将其从子模板转换文件更新到web.config之后。看起来这最后一步是用我想要的转换来覆盖web.config。
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.
我不确定最后一组复制指令的来源,所以我搜索了我的电脑上寻找其他wpp.target文件的所有文件。我在Slow Cheetah的扩展文件夹中找到了另一个,并看到一些顶部将一个属性“transformOnBuild”设置为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.
认为与SlowCheetah存在冲突,我将其卸载并且转换开始按预期工作。由于启用了SlowCheetah的其他解决方案,这仍然有点奇怪。一时兴起,我重新安装了SlowCheetah,转换继续按预期工作。
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.
所以我的解决方案最终是重新安装SlowCheetah。我仍然对这个问题的原因感到困惑,所以如果有人发布了这个问题的答案,我会给他们赏金。
#3
0
I've had a similar issue last week. Turns out that whenever you add a project to a solution in VS 2010 the right project configuration doesn't get applied all the time. So you think you have a configuration active but another is actually active on that project, thus the transformation you expect doesn't get applied.
我上周遇到了类似的问题。事实证明,无论何时将项目添加到VS 2010中的解决方案,都不会始终应用正确的项目配置。因此,您认为您的配置处于活动状态,但另一个配置实际上在该项目上处于活动状态,因此您预期的转换不会得到应用。
Check the steps in last comment of this issue: Custom solution configuration not showing up in Visual Studio 2010
检查此问题的最后评论中的步骤:自定义解决方案配置未显示在Visual Studio 2010中
#4
0
"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."
“我知道我正在使用的当前工作,因为它是唯一导致从web.template.xml重建web.config的工具,这种转换有效。只有子模板不起作用。”
Does this mean, transformation works but TestSettings section alone does not get transformed?
这是否意味着,转换是有效的,但单独的TestSettings部分不会被转换?
Can you share build output with msbuild with verbosity set to diagnostic / detailed?
你可以与msbuild共享构建输出,并将详细程度设置为诊断/详细吗?
#5
0
I wrote a blog post about this subject. I use it everyday in our web application. I wrote the blog post because the feature in slowcheetah isn't ready yet. http://www.locktar.nl/general/use-config-transforms-when-debugging-your-web-application/
我写了一篇关于这个主题的博客文章。我每天都在网络应用程序中使用它。我写博客文章是因为slowcheetah中的功能尚未准备就绪。 http://www.locktar.nl/general/use-config-transforms-when-debugging-your-web-application/