让Web.config文件转换本地工作 [英] Make Web.config transformations working locally

查看:161
本文介绍了让Web.config文件转换本地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要得到的web.config转换工作在本地,但显然的转化做部署的时候才会发生。

I want to get web.config transformations working locally but apparently the transformations only occur when doing deployments.

有谁知道的方式来运行的MSBuild目标TransformWebConfig没有它经历了重建的过程,还可以指定输出目录,吐出转化的web.config?

Does anybody know of a way to run the msbuild target "TransformWebConfig" without it going through the "rebuild" process and also specify and output directory where to spit out the transformed web.config?

修改:使用赛义德的回答,我创建了一个的.bat 文件来完成运行任务对我来说:

EDIT: Using Sayed's answer, I created a .bat file to do run the task for me:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Msbuild.exe "D:\Demo\Transformation.proj" /t:TransformWebConfig 

copy /Y  "D:\Demo\Web.config" "D:\MyProject\Web.config" 

del ""D:\Demo\Web.config"

在Transformation.proj是赛义德的code片段在下面的答案副本。只需指定源,目标和目的地的转变。新的文件,在这种情况下,转化的web.config将在D:\\演示目录中。我简单地复制过来重写我的项目的web.config,最后删除生成的文件中的演示文件夹中。

the "Transformation.proj" is a copy of Sayed's code snippet in the answer below. Just specify the source, target, and destination for the transformation. The new file, in this case, the transformed "web.config" will be in the "D:\Demo" directory. I am simply copying it over to overwrite my project's web.config and, finally, deleting the generated file in the "demo" folder.

另外,我创建了一个宏来运行这个批处理文件,对我进行改造的探讨:

Also, I created a macro to run this batch file and perform the tranformation for me:

Public Module DoTransform
    Sub RunTransformBatchFile()
        Try
          Process.Start("D:\Demo\RunTransform.bat")
        Catch ex As System.Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Module

您还可以添加一个按钮工具栏上运行该批处理和/或指定一个快捷键来执行。

You can also add a button on your toolbar to run this batch and/or assign a shortcut key to execute.

推荐答案

如果你想改变一个配置文件,而无需使用Web发布管道,那么你只需手动使用的TransformXML任务。我已经写了这个详细的博客文章在<一个href=\"http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx\">http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx,但这里有高灯:

if you want to transform a config file without using the Web Publishing Pipeline then you just use the TransformXml task manually. I've written a detailed blog post on this at http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx, but here are the high lights:

<Project ToolsVersion="4.0" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <UsingTask TaskName="TransformXml"
             AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

    <Target Name="Demo">
        <TransformXml Source="app.config"
                      Transform="Transform.xml"
                      Destination="app.prod.config"/>
    </Target>
</Project>

在这里我使用手动transform.xml文件转换app.config文件和目标文件是app.prod.config。

Here I manually transform the app.config file using transform.xml file and the destination file is app.prod.config.

这是你提到的在运行应用程序时是能够做局部改造一件事。为什么我们只执行转换软件包/发布的原因是因为如果我们改变的web.config本身那么下一次你调试你的应用程序中的web.config被再次转变。因此,例如,如果你的web.debug.config你必须转型,一个增值的配置,一切都OK了你第一次添加,但再下一次你运行/调试你的应用程序将再次得到补充。所以,最好是避免这种情况。

One thing that you mentioned was being able to do transformation locally when running the app. The reason why we only perform the transform on package/publish is because if we transformed web.config itself then next time you debug your app the web.config gets transformed again. So for example if in your web.debug.config you have the transformation to add a value to config, everything is OK the first time you add that but then the next time your run/debug your app it will get added again. So it is best to avoid that.

这篇关于让Web.config文件转换本地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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