gpt4 book ai didi

.net - 为什么我的 Web 应用程序在调试运行时不使用 Web.Debug.config?

转载 作者:行者123 更新时间:2023-12-02 01:42:43 24 4
gpt4 key购买 nike

Possible Duplicate:
Use Visual Studio web.config transform for debugging

我有一个带有三个 web.config 转换的 asp.net 应用程序。

enter image description here

我在想,当我启动调试运行(选择 Debug模式下的 F5)时,Web.Debug.config 中编写的转换将适用。但它不起作用。使用的 Web.config 是“Base”一个。

你会告诉我:“转换不正确”..但它们是因为当我使用调试发布配置进行部署(右键单击/发布)时: enter image description here

渲染后的 web.config 有修改!所以它可以工作,但是调试运行正在使用基本的 web.config.. 有没有地方可以配置它?

最佳答案

编辑:可以在 SO 上找到更精致的方法: Use Visual Studio web.config transform for debugging

我曾评论说我也喜欢这个功能,但还没有找到实现它的方法。然后决定快速谷歌一下。

讨论here让我找到了 cmac3095 提供的一种可能的解决方案:

I don't mess with MSBUILD that much but my solution was to add a custom target to the XXX.Web.csproj that did the transform and then add a custom "Post build" event to the XXX.Web.csproj that invoked MSBUILD (to perform the transform) and an XCOPY to copy the transformed web.config over the original. One side effect is that, as we have TFS, it always contains the last web.config that was transformed which can be a bit usettling (you keep thinking one of your other developers has overwritten your settings - which, in a sense, they have ;-)....but, of course, your settings are in the web.xxxxxx.config you use in the transform. Okay, enough explanation.
Here's what you do: Copy and paste this into you XXXX.Web.csproj just above the commented out "Target Name="BeforeBuild" element...

<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"
/> <Target Name="Transform">
<MakeDir Directories="obj\$(Configuration)"
Condition="!Exists('obj\$(Configuration)')"
/>
<TransformXml Source="Web.Config" Transform="Web.$(Configuration).config"
Destination="obj\$(Configuration)\Web.config"
StackTrace="true" /> </Target>
<Target Name="AfterBuild">
</Target>

That's it. On the next build of your xxx.web.config, the post build will run the custom target and generate transformed web.config. The XCOPY will overwrite the existing.

关于.net - 为什么我的 Web 应用程序在调试运行时不使用 Web.Debug.config?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6579158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com