Using MSBuild Extension pack to Deploy Code - Need to update configuration file before MSBuild is called to compile code?

May 6, 2013 at 9:14 PM
Does anyone know how I can,in the targets.XML file, declare what a value should be within a configuration file before calling the <MSBuild> command to compile the code?

I've been told I can use this Copy command to do this but I'm not sure which subcommand to use to be able to update the configuration file.:
 <Copy Condition="'$(type)'=='XX'"
           SourceFiles="$(SolutionPath)\$(project)\"
            DestinationFolder="$(DeployProjectFolder)"
        />
Coordinator
May 9, 2013 at 12:17 PM
I'm not following. Can you provide a bit more info on what you need to do.

thanks

Mike
May 9, 2013 at 2:13 PM

Hi,

Yes, I can definitely clarify, so below is a snippet of target.xml file I’m working on to help with the packaging of the different components that make up the application I release. I have found that one scheduled task app.config needs to be updated before the <MSBuild> command gets executed. I have tried searching but there are so many ways that I’m confused as to what is the best way. I have colleague that said that I could use the <copy> command and update the file I guess before I copied to the proper project folder but I’m not sure what he means. Looking at the <Copy> sub-commands I didn’t see any that would allow me to edit a value within the app.config and then copy it to the appropriate destination folder. The highlighted portion is the target I’m trying to get correct.

Does this help?

<Target Name="Update App Config">

<Copy Condition="'$(output)'=='XXX_Hourly_Update'"

SourceFiles="$(SolutionPath)\$(project)\app.config\"

DestinationFolder="$(DeployProjectFolder)"/>

</Target>

<Target Name="Deploy">

<!-- Build the Scheduled tasks and service projects -->

<MSBuild Projects="$(ProjectPath)\$(project).vbproj"

Targets="Rebuild;ResolveReferences"

Properties="OutputPath=$(DeployProjectFolder);

WebProjectOutputDir=$(DeployProjectFolder);

OutDir=$(DeployProjectFolder)\bin\;

Configuration=$(configuration);" />

<!—app.cofnig and web.config transformation.-->

<TransformXml Condition="'$(type)'=='ScheduledTask'"

Source="$(ProjectPath)\app.config"

Transform="$(ProjectPath)\app.$(configuration).config"

Destination="$(DeployProjectFolder)\app.config"

StackTrace="$(StackTraceEnabled)" />

<TransformXml Condition="'$(type)'=='Services'"

Source="$(ProjectPath)\Web.config"

Transform="$(ProjectPath)\Web.$(configuration).config"

Destination="$(DeployProjectFolder)\Web.config"

StackTrace="$(StackTraceEnabled)" />

<TransformXml Condition="'$(type)'=='WWW'"

Source="$(ProjectPath)\Web.config"

Transform="$(ProjectPath)\Web.$(configuration).config"

Destination="$(DeployProjectFolder)\Web.config"

StackTrace="$(StackTraceEnabled)" />

<!-- Delete the legacy web.config or app.config transformation files from output -->

<Delete Condition ="'$(type)'=='ScheduledTask'"

Files="$(DeployProjectFolder)\app.config

$(DeployProjectFolder)\app.debug.config;

$(DeployProjectFolder)\app.dev.config;

$(DeployProjectFolder)\app.release.config;

$(DeployProjectFolder)\app.staging.config;

$(DeployProjectFolder)\app.qa.config;

$(DeployProjectFolder)\app.production.config;

$(DeployProjectFolder)\app.stagingrw.config;

$(DeployProjectFolder)\app.productionrw.config" />

<Delete Condition="'$(type)'=='Services'"

Files="$(DeployProjectFolder)\web.debug.config;

$(DeployProjectFolder)\web.dev.config;

$(DeployProjectFolder)\web.release.config;

$(DeployProjectFolder)\web.staging.config;

$(DeployProjectFolder)\web.qa.config;

$(DeployProjectFolder)\web.production.config;

$(DeployProjectFolder)\web.stagingrw.config;

$(DeployProjectFolder)\web.productionrw.config" />

<Delete Condition="'$(type)'=='WWW'"

Files="$(DeployProjectFolder)\web.debug.config;

$(DeployProjectFolder)\web.dev.config;

$(DeployProjectFolder)\web.release.config;

$(DeployProjectFolder)\web.staging.config;

$(DeployProjectFolder)\web.qa.config;

$(DeployProjectFolder)\web.production.config;

$(DeployProjectFolder)\web.stagingrw.config;

$(DeployProjectFolder)\web.productionrw.config" />

Coordinator
May 10, 2013 at 12:16 PM
Ok so you have a bespoke process, i.e. this isn't part of project compilation.

you could have a 2nd copy of the file with the right content and then copy that, or you could call a task to edit the file content before doing it. Again, you have options, like doing regex replace or xml editing.

See: http://www.msbuildextensionpack.com/help/4.0.7.0/?topic=html/f8c545f9-d58f-640e-3fce-b10aa158ca95.htm for replace and http://www.msbuildextensionpack.com/help/4.0.7.0/?topic=html/4009fe8c-73c1-154f-ee8c-e9fda7f5fd96.htm for xml

Mike
Marked as answer by mikeFourie on 10/9/2013 at 3:15 PM