当前位置: 动力学知识库 > 问答 > 编程问答 >

MSBuild property and variable overloading

问题描述:

Let's say I launch a build script, definition named SampleScript , specifying the parameter /p:MyPrefix=Custom. There is the following code in the script:

<PropertyGroup Condition="$(BuildDefinitionName)=='SampleScript'">

<MyPrefix>Default</MyPrefix>

</PropertyGroup>

As I get, first MyPrefix is set to "Custom", then it's overloaded to "Default" (am I right?). If so, is there any way to make a user-specified parameter more prioritized, so it's not overloaded?

网友答案:

You can only overload a property specified on the command line by dynamically changing the value inside a target...

<Project ...>
   <PropertyGroup>
      <Value>FromStaticProperty</Value>
   </PropertyGroup>

   <Target Name="PropertyPrecedence">
      <Message Text="Value = '$(Value)'" />
      <PropertyGroup>
         <Value>FromDynamicProperty</Value>
      </PropertyGroup>
      <Message Text="Value = '$(Value)'" />
   </Target>
</Project>

> msbuild /p:Value=FromCommandLine

In the above example, the "FromStaticProperty" will be ignored given the value supplied from the command line, but the "FromDynamicProperty" will be used.

Excerpted from MSBuild Trickery trick #27

分享给朋友:
您可能感兴趣的文章:
随机阅读: