MSBuild passing parameters to CallTarget

MSBuild targets aren’t designed to receive parameters. Instead, they use the properties you define for them.

<PropertyGroup>
    <Environment>myValue</Environment>
</PropertyGroup>

<Target Name="Deploy">
    <!-- Use the Environment property -->
</Target>

However, a common scenario is to invoke a Target several times with different parameters (i.e. Deploy several websites). In that case, I use the MSBuild MSBuild task and send the parameters as Properties:

<Target Name="DoDeployments">
    <MSBuild Projects ="$(MSBuildProjectFullPath)"
             Properties="VDir=MyWebsite;Path=C:\MyWebsite;Environment=$(Environment)"
             Targets="Deploy" />

    <MSBuild Projects ="$(MSBuildProjectFullPath)"
             Properties="VDir=MyWebsite2;Path=C:\MyWebsite2;Environment=$(Environment)"
             Targets="Deploy" />
</Target>

$(MSBuildProjectFullPath) is the fullpath of the current MSBuild script in case you don’t want to send “Deploy” to another file.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)