Skip to content

Instantly share code, notes, and snippets.

@rschiefer
Created April 26, 2016 19:12
Show Gist options
  • Save rschiefer/428a8c6de9dfc43e8b48c8181970fc9f to your computer and use it in GitHub Desktop.
Save rschiefer/428a8c6de9dfc43e8b48c8181970fc9f to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OnAfterPipelineCollectFilesPhase>
$(OnAfterPipelineCollectFilesPhase);
MSDeploySetParametersFile;
MSDeploySetParameters;
MSDeploySetParametersUpdate;
</OnAfterPipelineCollectFilesPhase>
</PropertyGroup>
<PropertyGroup>
<!--<MSDeployPublishSetParametersFile>SetParameters.Test.xml</MSDeployPublishSetParametersFile>-->
<!--<MSDeployPublishSetParameters>testSetting='changed_fromSetParam';IIS Web Application Name='Default Web Site/app13'</MSDeployPublishSetParameters>-->
<MSDeployPublishSetParametersPriority>-100</MSDeployPublishSetParametersPriority>
</PropertyGroup>
<!-- Sample Usage: msdeploy.exe ... /p:MSDeployPublishSetParameters=testSetting='changed_fromSetParam';IIS Web Application Name='Default Web Site/app13' -->
<!-- Seperate parameters with a semicolon (;)-->
<!-- Seperate name and value with an equal sign (=)-->
<!-- Surround values with an apostophe (')-->
<Target Name="MSDeploySetParameters" Condition="'$(MSDeployPublishSetParameters)'!=''" BeforeTargets="MSDeployPublish">
<ItemGroup>
<SetParameterArguments Include="$(MSDeployPublishSetParameters)" />
<SetParameters Include="$([System.Text.RegularExpressions.Regex]::Match(%(SetParameterArguments.Identity), `[^=]*(?==)`))">
<value>$([System.Text.RegularExpressions.Regex]::Match(%(SetParameterArguments.Identity), `(?&lt;==')[^']*`))</value>
</SetParameters>
</ItemGroup>
</Target>
<!-- Sample Usage: msdeploy.exe ... /p:MSDeployPublishSetParametersFile=SetParameters.Test.xml -->
<Target Name="MSDeploySetParametersFile" Condition="'$(MSDeployPublishSetParametersFile)'!=''" BeforeTargets="MSDeployPublish">
<XmlPeek
XmlInputPath="$(MSDeployPublishSetParametersFile)"
Query="/child::node()/child::node()">
<Output TaskParameter="Result" ItemName="SetParameterNodes" />
</XmlPeek>
<ItemGroup>
<SetParameters Include="$([System.Text.RegularExpressions.Regex]::Match(%(SetParameterNodes.Identity), `(?&lt;=name=&quot;)[^&quot;]*`))">
<value>$([System.Text.RegularExpressions.Regex]::Match(%(SetParameterNodes.Identity), `(?&lt;=value=&quot;)[^&quot;]*`))</value>
</SetParameters>
</ItemGroup>
</Target>
<Target Name="MSDeploySetParametersUpdate" >
<Message Text="%(SetParameters.Identity),%(SetParameters.value)" />
<ItemGroup>
<MsDeployDeclareParameters Include="%(SetParameters.Identity)">
<DefaultValue>%(SetParameters.value)</DefaultValue>
<Priority>$(MSDeployPublishSetParametersPriority)</Priority>
</MsDeployDeclareParameters>
</ItemGroup>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment