Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling TransformWebConfig on a solution file

I have a solution with multiple projects in it one of these projects is a web application and I would like to be able to transform the web.config using web.release.config when building the solution using MSBuild. When I call

MSBuild "WebProject.csproj" /t:TransformWebConfig /p:Configuration=Release

on the web project I get the transformed web.config output to ...\obj\Release\TransformWebConfig\transformed\ Web.config

but when I try to call

MSBuild "Solution.sln" /t:TransformWebConfig /p:Configuration=Release

I get an error that "TransformWebConfig does not exist in the project". Is there a you to get this to work so it will output a transformed web.config if possible and ignore the TransformWebConfig part of the command otherwise?

like image 486
Jason Quinn Avatar asked Sep 12 '25 09:09

Jason Quinn


1 Answers

The easiest way to do this seems to be to change the web projects .csproj file to

<Project ToolsVersion="4.0" DefaultTargets="BuildWithConfig" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

And then add a new target

<Target Name="BuildWithConfig">
    <CallTarget Targets="Build"/>
    <CallTarget Targets="TransformWebConfig"/>
</Target>

And then run

MSBuild "Solution.sln" /p:Configuration=Release

And the file will be output to ...\WebProject\obj\Release\TransformWebConfig\transformed

like image 56
Jason Quinn Avatar answered Sep 15 '25 08:09

Jason Quinn