Pergunta

I currently have to have two separate property groups with only two differences between them, that are set to have one or the other trigger depending on a condition. Here's what I have:

<!--CAME FROM TEAMBUILD-->
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' != 'Debug|AnyCPU' AND '$(Configuration)|$(Platform)' != 'Release|AnyCPU' AND '$(BuildingInsideVisualStudio)' != 'true' ">
    <PreBuildEvent>
    </PreBuildEvent>
    <PostBuildEvent>
      set MAGE="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\mage.exe"
      set APPFILE=$(TargetDir)$(TargetName).application
      set MANIFEST=$(TargetPath).manifest
      set CERT=$(ProjectDir)$(TargetName).pfx
      set PROJECTNAME=$(TargetName)
      set CONFIGURATION=$(ConfigurationName)
      set TARGETDIR=$(TargetDir)
      set TEAMBUILD=$True
      Powershell -File "$(ProjectDir)POSTBUILD.ps1"
    </PostBuildEvent>
  </PropertyGroup>

  <!--CAME FROM PUBLISH COMMAND-->
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' != 'Debug|AnyCPU' AND '$(Configuration)|$(Platform)' != 'Release|AnyCPU' AND '$(BuildingInsideVisualStudio)' == 'true' ">
    <PreBuildEvent>
    </PreBuildEvent>
    <PostBuildEvent>
      set MAGE="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\mage.exe"
      set APPFILE=$(TargetDir)$(TargetName).application
      set MANIFEST=$(TargetPath).manifest
      set CERT=$(ProjectDir)$(TargetName).pfx
      set PROJECTNAME=$(TargetName)
      set CONFIGURATION=$(ConfigurationName)
      set TARGETDIR=$(TargetDir)
      set TEAMBUILD=$False
      Powershell -File "$(ProjectDir)POSTBUILD.ps1"
    </PostBuildEvent>
  </PropertyGroup>

Is there a way to set the teambuild value based on the $(BuildingInsideVisualStudio) value inside the post build event? Something like

If ($(BuildingInsideVisualStudio) == 'true') set TEAMBUILD = $True

or even something like set TEAMBUILD = $$(BuildingInsideVisualStudio) ?

Foi útil?

Solução

You're already using it: Condition. You just have to extract an extra step to create a property that will be used as the TEAMBUILD value. For example:

<PropertyGroup Condition='$(BuildingInsideVisualStudio)' != 'true' ">
  <TeamBuildValue>FALSE</TeamBuildValue>
</PropertyGroup>

<PropertyGroup Condition='$(BuildingInsideVisualStudio)' == 'true' ">
  <TeamBuildValue>TRUE</TeamBuildValue>
</PropertyGroup>

<PropertyGroup>
  <PreBuildEvent>
  </PreBuildEvent>
  <PostBuildEvent>
    ...
    set TEAMBUILD=$(TeamBuildValue)
    ...
  </PostBuildEvent>
</PropertyGroup>

Outras dicas

I would probably try a Choose/Otherwise.......instead of a == != Just a preference. Because one day.....you may have a third option.

the "Otherwise" clause (aka , use some default values) is more explicit.

<Choose>

    <When Condition=" '$(Computername)'=='MySuperComputer01' ">               
        <PropertyGroup>
            <FavoriteFood>Peanuts</FavoriteFood>
            <FavoriteColor>Red</FavoriteColor>
        </PropertyGroup>
    </When>

    <When Condition=" '$(Computername)'=='MySuperComputer02' ">
        <PropertyGroup>
            <FavoriteFood>Apples</FavoriteFood>
            <FavoriteColor>Yellow</FavoriteColor>
        </PropertyGroup>
    </When>

    <Otherwise>
        <PropertyGroup>
            <FavoriteFood>CrackersDefault</FavoriteFood>
            <FavoriteColor>OrangeDefault</FavoriteColor>
        </PropertyGroup>        
    </Otherwise>
    
</Choose>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top