MSBuild: Update Custom Project Property
I am trying to update the following custom property during my build (this is the custom property in one of my project files:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestVersion>False</TestVersion>
I have tried using UpdateElement with the MSBuild Extension Pack. I also tried setting it with the properties settings of "SolutionToBuild" but that doesn't seem to set the value.
Some things I have tried:
<ItemGroup>
<SolutionToBuild Include="$(BuildProjectFolderPath)/../../$(SuiteSourceBranchRoot)/开发者_JAVA技巧Source/XXX/Suite.sln">
<Targets></Targets>
<Properties>TestVersion=True;</Properties>
<CustomPropertiesForBuild>TestVersion=True;</CustomPropertiesForBuild>
</SolutionToBuild>
</ItemGroup>
<XmlFile
File ="$(SolutionRoot)\$(SuiteSourceBranchRoot)\Source\XXX\XXX\Sample.csproj"
TaskAction="UpdateElement"
XPath="/Project/PropertyGroup/TestVersion"
InnerText="True"
/>
I need this value set in two projects because I have a choose when that will key off of this value.
Thank you.
Try using AdditionalProperties,
<ItemGroup>
<SolutionToBuild Include=".../Suite.sln">
<Targets></Targets>
<AdditionalProperties>TestVersion=True</AdditionalProperties>
</SolutionToBuild>
</ItemGroup>
Now doing this (or using Properties as you have above) will only apply when the item array you are creating, in this case @(SolutionToBuild) is passed to the MSBuild task.
It is a little tough from your question to see what you are trying to do, but using XML to change the project file is not the way to go. Depending on what you are trying to do there is a proper way to alter the property. What is the scenerio for changing this property? Is it from the command line, or from a build machine script?
To allow overriding the property, only set its default value if no value is set:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestVersion Condition="'$(TestVersion)' != ''">False</TestVersion>
精彩评论