Jer*_*rry 6 c# asp.net-mvc web-config visual-studio-2010 visual-studio
我正在尝试按照此处所述进行web.config转换.我们已经在其他项目中使用了这种方法,它没有问题,但在这个新项目上没有.
这是我试过没有成功的测试
我已经多次阅读了上面的链接和这个相关的堆栈问题,但看不出是什么问题.
注意发布转换确实有效.它创建一个web.template.xml文件,其中包含来自web.template.Test.xml的值,但不会像wpp.targets指示的那样创建web.config.xml.因此,这似乎是让构建转换正常工作的问题.
任何人都知道缺少什么?
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
MSBuild输出
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)
Run Code Online (Sandbox Code Playgroud)
我已经找到了解决问题的方法,但不确定原因是什么,因此不确定这是否能在其他情况下解决问题。
我查看了 MSBuild 诊断的输出,注意到最后有另一个部分将 web.template 复制到 web.config。请注意,这是在 UpdateWebConfigBeforeRun 目标已经运行并从子模板转换文件更新到 web.config 之后发生的。看起来最后一步是用我想要的转换覆盖 web.config 。
我不确定这最后一组复制指令来自哪里,因此我搜索了我的电脑上的所有文件,寻找其他 wpp.target 文件。我在 Slow Cheetah 的扩展文件夹中找到了另一个扩展,并看到顶部的某些部分将属性“transformOnBuild”设置为 false。
我认为与 SlowCheetah 存在冲突,因此将其卸载,并且转换开始按预期工作。这仍然有点奇怪,因为其他解决方案都启用了 SlowCheetah。一时兴起,我重新安装了 SlowCheetah,转换继续按预期进行。
所以我的解决方案最终是重新安装 SlowCheetah。我仍然对这个问题的原因感到困惑,所以如果其他人发布了这个问题的答案,我会给他们赏金。
| 归档时间: |
|
| 查看次数: |
2871 次 |
| 最近记录: |