mahars
mahars

Reputation: 41

is there a whatif switch for msbuild command line?

I have a msbuild command line running on my build server. It is deploying after build with the switch /p:DeployOnBuild=true

Is there a switch like whatif for msbuild on deploy?

Upvotes: 1

Views: 446

Answers (1)

Alexander
Alexander

Reputation: 4527

There are several ways to implement the issue within continious integration.

Custom MSBuild task

You could create your own task that implements ITask interface. You could just derive your task from the helper class Task and override its Execute() method. This solution is most flexible. So, it is possible to pass additional parameters from command line to deploing process or hardcode them in dependence on build configuration.

Then add the task to your project:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <!-- Register the custom task -->
    <UsingTask TaskName="TaskNamespace.MyTask" AssemblyFile="path\to\task\assembly.dll"/>

    <!-- Define something -->

    <!-- Set properties for Debug configuration -->
    <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
        <WhatIf>true</WhatIf>
        <!-- Set another properties -->
    </PropertyGroup>

    <!-- Set properties for Release configuration -->
    <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
        <WhatIf>false</WhatIf>
        <!-- Set another properties -->
    </PropertyGroup>

    <Target Name="MyTarget">  
        <MyTask OnlyReport="$(WhatIf)"/>  
    </Target>  
</Project>

See detailed indormation in the Task Writing article.

Different commands

It is possible to build your project and create a web package using msbuild, then create report of the package deploying using msdeploy or .deploy.cmd file. For example

msbuild "MySolution.sln" /t:MyProject /p:Configuration="Release" /p:DeployOnBuild=true /p:PublishProfile="Local Package"
"path\to\MyProject.deploy.cmd" /T /M:"http://my-server.loc/MsDeployAgentService" /A:NTLM -allowUntrusted

The first command builds your web application project and creates local web deploy package. Note, it requires Local Package publication profile in your solution file.

The second line calls msdeploy.exe with the –whatif flag. Also it is possible to use msdeploy.exe directly. To get detailed information see Deploying Web Packages.

Automating Web Package Deployment

Previous way could be automated using <Exec> task of MSBuild. For example

<PropertyGroup>
    <DeployMode>T</DeployMode>
    <DeployMode Condition=" '$(Configuration)'=='Release' ">Y</DeployMode>
    <DestinationServer>http://my-server.loc</DestinationServer>
</PropertyGroup>
<Target Name="PublishWebPackages">
    <PropertyGroup>
        <DeployCommand>
          "path\to\MyProject.deploy.cmd" /$(DeployMode) /M:$(DestinationServer)/MsDeployAgentService /A:NTLM
        </DeployCommand>
    </PropertyGroup>
    <Exec Command="$(DeployCommand)"/>
</Target>

You could also pass values of DeployMode and DestinationServer through msbuild command /p: switches.

Upvotes: 1

Related Questions