Web.config conversion works locally

I want the web.config transformations to work locally, but apparently the transformations only happen during deployment.

Does anyone know a way to run the msbuild target "TransformWebConfig" without going through the "rebuild" process, and also point and list the directory where to spit the converted web.config?

EDIT : using Sayed's answer, I created a .bat file to complete 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" is a copy of the Sayed code snippet in the answer below. Just indicate the source, purpose and destination for the conversion. The new file, in this case, the converted "web.config" will be located in the directory "D: \ Demo". I just copy it to overwrite my web.config project and finally delete the generated file in the demo folder.

In addition, I created a macro to run this batch file and performed the conversion 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 the toolbar to launch this part and / or assign a key combination.

+33
web-config visual-studio-2010 web-deployment msdeploy
Aug. 31 '10 at 22:36
source share
2 answers

if you want to convert the configuration file without using web publishing, then you just use the TransformXml task manually. I wrote a detailed blog post about this at http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx , but here are the bright 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> 

Here, I manually convert the app.config file using the transform.xml file and the target file is app.prod.config.

One thing you were talking about was able to do the conversion locally when the application started. The reason we only do the conversion in the package / publication is because if we change the web.config itself, then the next time you debug your application, the web.config is converted again. So, for example, if in your web.debug.config you have a conversion for adding a value to config, everything will be fine when you add it, but the next time you start / debug your application, it will be added again. Therefore, it is better to avoid this.

+34
Sep 01 '10 at 3:38
source share

If you are using Visual Studio 2015, you can simply right-click on the transformation of the desired environment and click "View Preview" ... Then it will generate the conversion, and you can copy and paste it into a regular Web.config file for debugging purposes. Just don't do it!

If you are using Visual Studio 2013, you can install the SlowCheetah extension - XML ​​Transforms

+2
Oct 10 '16 at 22:46
source share



All Articles