Tôi đang cố gắng chuyển đổi web.config hoạt động như được mô tả here. Chúng tôi đã sử dụng phương pháp này trên các dự án khác và nó hoạt động mà không có vấn đề, nhưng không phải trên dự án mới này.chuyển đổi web.config từ web.template.xml không hoạt động
Đây là những gì tôi đã cố gắng thử nghiệm không thành công
- Thay đổi tên của tập tin wpp.targets trong trường hợp tôi có tên dự án sai. Tôi biết một trong những hiện tại tôi đang sử dụng công trình vì nó là người duy nhất gây ra web.config được xây dựng lại từ web.template.xml biến đổi này hoạt động. Chỉ các mẫu phụ không hoạt động.
- Cố gắng với xdt: Locator = "trận đấu (tên)"
- Cố gắng .config mở rộng vs .xml, các dự án khác của chúng tôi nơi này hoạt động sử dụng .xml
- quản lý cấu hình được thiết lập để sử dụng "Test" cấu hình cho dự án tôi đang làm.
- web.template.Test.xml đã xdt: chuyển = "Thay thế" cho phần tôi muốn thay thế
- web.template.xml có placeholder
- Cố gắng loại bỏ các "CopyWebTemplateConfig" đoạn từ wpp.targets như được đề xuất trên câu hỏi ngăn xếp được liên kết bên dưới. Các dự án khác của chúng tôi có điều này và phần "PropertyGroup" đã nhận xét và tôi đã thử cả hai kết hợp.
Tôi đã đọc qua liên kết ở trên nhiều lần và ngăn xếp liên quan này question, nhưng không thể xem vấn đề là gì.
Lưu ý Biến đổi xuất bản hoạt động theo cách. Nó tạo ra một tệp tin web.template.xml chứa các giá trị từ web.template.Test.xml, nhưng không tạo ra một tệp web.config.xml như các hướng dẫn wpp.targets. Vì vậy, đây là một vấn đề với việc chuyển đổi xây dựng làm việc có vẻ như.
Bất kỳ ai có ý tưởng về những gì còn thiếu?
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>
Đầu ra 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)
Bạn có thể gửi cho tôi dự án mẫu không hoạt động không? Email của tôi là sayedha [at] {MicrosoftDOTcom}. –