从命令行运行 web.config 转换

发布于 2024-10-14 23:52:12 字数 416 浏览 2 评论 0原文

再会!

我希望能够使用 VS2010 发布对话框从命令行构建 ASP.NET MVC 2 项目。

对于命令行,我得到以下工作:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe .\SolutionFolder\MyProject.csproj /p:Configuration=Release;DeployOnBuild=True;PackageAsSingleFile=False;outdir=c:\_OutputFolder\

我遇到的唯一问题是 Web.config 转换未应用(但添加到 WebDeploy 包中)。我不使用 WebDeploy。有什么方法可以应用 Web.config 转换吗?

谢谢!

Good day!

I want to have ability to build ASP.NET MVC 2 project using VS2010 Publish dialog and from command-line.

For command-line I get the following to work:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe .\SolutionFolder\MyProject.csproj /p:Configuration=Release;DeployOnBuild=True;PackageAsSingleFile=False;outdir=c:\_OutputFolder\

The only problem I have that Web.config transformation are not applied (but added to WebDeploy package). I don't use WebDeploy. Is there any way to apply Web.config transformations?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

宛菡 2024-10-21 23:52:12

您还可以尝试使用 XDT 转换工具:

http://ctt.codeplex.com 已移至 Github
https://github.com/greenfinch/ctt

我正在使用它,而不是搞乱晦涩的 msbuild目标。

You can also try using the XDT Transformation Tool:

http://ctt.codeplex.com was moved to Github
https://github.com/greenfinch/ctt

I'm using this instead of messing with obscure msbuild targets.

双马尾 2024-10-21 23:52:12

这是另一种方法,它使用 msbuild 转换 Web.config 文件:

http://sedodream。 com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx

在我的测试中,结果更好。基本上,您创建一个项目文件仅执行 TransformXML 任务:

<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>

保存项目文件,然后应用转换,运行以下命令:

msbuild trans.proj /t:演示

其中 trans.proj 是项目文件的名称,Demo 是任务目标的名称。

Here is another approach, which uses msbuild to transform Web.config file:

http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx

In my tests the results were better. Basically, you create a project file to perform only a TransformXML task:

<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>

Save the project file and then apply the transformation, running the following command:

msbuild trans.proj /t:Demo

Where trans.proj is the name of the project file and Demo is the name of task target.

等你爱我 2024-10-21 23:52:12

我认为值得一提的是,您还可以将 Visual Studio 使用的 DLL 与 PowerShell 一起使用:Microsoft.Web.XmlTransform.dll

PowerShell 脚本,请参阅:Web.Config 在 Microsoft MSBuild 之外进行转换?

加载 DLL 而不是四处复制,我确实喜欢这样(所以你知道在哪里可以找到这个 DLL,至少在我的工作场景中我们必须查找这些位置):

if (Test-Path "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.XmlTransform.dll") {
    Add-Type -LiteralPath "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.XmlTransform.dll"
} elseif (Test-Path "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.XmlTransform.dll") {
    Add-Type -LiteralPath "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.XmlTransform.dll"
} else {
    throw [System.IO.FileNotFoundException] "Microsoft.Web.XmlTransform.dll not found."
}

I think it's worth to mention that you can also use with PowerShell the DLL that Visual Studio is using: Microsoft.Web.XmlTransform.dll

PowerShell script, see: Web.Config transforms outside of Microsoft MSBuild?

To load the DLL instead of copying around, I do like this (so you see where to find this DLL, at least in my scenario at work we had to look-up these locations):

if (Test-Path "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.XmlTransform.dll") {
    Add-Type -LiteralPath "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.XmlTransform.dll"
} elseif (Test-Path "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.XmlTransform.dll") {
    Add-Type -LiteralPath "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.XmlTransform.dll"
} else {
    throw [System.IO.FileNotFoundException] "Microsoft.Web.XmlTransform.dll not found."
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文