MSBuild使用导入覆盖属性值

MSBuild使用导入覆盖属性值,msbuild,msbuild-task,Msbuild,Msbuild Task,我有一个msbuild脚本,它只包含PropertyGroup:DefaultVariables.msbuild <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <!-- default values if nothing is set in Main.proj --> <PropertyGroup> <ProjectName Condition=

我有一个msbuild脚本,它只包含PropertyGroup:DefaultVariables.msbuild

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- default values if nothing is set in Main.proj -->
  <PropertyGroup>
    <ProjectName Condition="'$(PublishService)'==''">DefaultService</ProjectName>
  </PropertyGroup>
</Project>

默认服务
出版服务可以根据环境而改变。 我还有一个Variables.msbuild,除服务名称外,与上述脚本相同:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- default values if nothing is set in Main.proj -->
  <PropertyGroup>
    <ProjectName Condition="'$(PublishService)'==''">ErpService</ProjectName>
  </PropertyGroup>
</Project

ERP服务

首先,你永远不会给
PublishService
一个值。我假设在DefaultVariables.msbuild中,您想要做的是

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- default values if nothing is set in Main.proj -->
  <PropertyGroup>
    <PublishService> Condition="'$(PublishService)'==''">DefaultService</PublishService>
  </PropertyGroup>
</Project>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CreateInstaller">

  <Import Project="Variables.msbuild" />
  <Target Name="CreateBatchScripts">
    <Message Text="PublishService = $(PublishService)" />
  </Target>
</Project>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- default values if nothing is set in Main.proj -->
  <PropertyGroup>
    <PublishService> Condition="'$(PublishService)'==''">DefaultService</PublishService>
  </PropertyGroup>
</Project>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <PublishService>ErpService</PublishService>
  </PropertyGroup>
</Project>