[ACCEPTED]-Overwrite properties with MSBuild-msbuild
Accepted answer
Mehmet is right about how to set a property 4 value from another property, but there is 3 a bug/feature in MSBuild which means that 2 if you call CreateProperty and CallTarget in the same Target, your new property will not be globally available to other targets (described here).
So here is the final solution to the 1 problem:
<PropertyGroup>
<DeployPath_TEST>\\test-server-path\websites\mysite</DeployPath_TEST>
<DeployPath_LIVE>\\live-server-path\websites\mysite</DeployPath_LIVE>
<DeployPath></DeployPath>
</PropertyGroup>
<Target Name="SetDeployPath-TEST">
<CreateProperty Value="$(DeployPath_TEST)">
<Output TaskParameter="Value" PropertyName="DeployPath"/>
</CreateProperty>
</Target>
<Target Name="Deploy-TEST">
<CallTarget Targets="SetDeployPath-TEST"/>
<CallTarget Targets="Deploy-Sub"/>
</Target>
<Target Name="Deploy-Sub">
<Message Text="Deploying to $(DeployPath)"/>
<MSBuild Projects="MySolution.csproj" Targets="Rebuild" />
<ItemGroup>
<MyFiles Include="**\*"/>
</ItemGroup>
<Copy SourceFiles="@(MyFiles)"
DestinationFiles="@(MyFiles->'$(DeploymentPath)\%(RecursiveDir)%(FileName)%(Extension)')"/>
</Target>
You can use CreateProperty task to overwrite the value 1 of an existing property.
<Target Name="Deploy-LIVE">
<CreateProperty Value="$(DeployPath_LIVE)">
<Output PropertyName="DeployPath" TaskParameter="Value"/>
</CreateProperty>
<CallTarget Targets="Deploy-Sub"/>
</Target>
Besides, you can use following way:
<PropertyGroup>
<DeployPath_TEST>\\test-server-path\websites\mysite</DeployPath_TEST>
<DeployPath_LIVE>\\live-server-path\websites\mysite</DeployPath_LIVE>
<DeployPath></DeployPath>
</PropertyGroup>
<Target Name="SetDeployPath-TEST">
<CreateProperty Value="$(DeployPath_TEST)">
<Output TaskParameter="Value" PropertyName="DeployPath"/>
</CreateProperty>
</Target>
<Target Name="Deploy-Sub" DependsOnTargets="SetDeployPath-TEST">
<Message Text="Deploying to $(DeployPath)"/>
<MSBuild Projects="MySolution.csproj" Targets="Rebuild" />
<ItemGroup>
<MyFiles Include="**\*"/>
</ItemGroup>
<Copy SourceFiles="@(MyFiles)"
DestinationFiles="@(MyFiles->'$(DeploymentPath)\%(RecursiveDir)%(FileName)%(Extension)')"/>
</Target>
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.