开发者

Run web.config transformation from command-line

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:Configur开发者_运维技巧ation=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!


You can also try using the XDT Transformation Tool:

http://ctt.codeplex.com

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


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.


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."
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜