How to ignore the property value specified on the command line from the corresponding csproj file?

Our TFS build controllers collect all projects from the same solution into the same bin directory, because the TFS build workflow passes the parameter OutDirto the msbuild command, which is responsible for building the solution.

I have a project in which I want to suppress this behavior and allow it to be embedded in the standard relative directory bin\Debugor bin\Release.

But I can not find how to do it. In fact, pay attention to the following trivial msbuild script:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <OutDir>$(MSBuildThisFileDirectory)bin\$(Configuration)</OutDir>
  </PropertyGroup>
  <Target Name="Build">
      <Message Text="$(OutDir)" Importance="High"/>
  </Target>
</Project>

Now I run it:

PS C:\> msbuild .\1.csproj /p:OutDir=XoXo /nologo
Build started 11/13/2015 9:50:57 PM.
Project "C:\1.csproj" on node 1 (default targets).
Build:
  XoXo
Done Building Project "C:\1.csproj" (default targets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.03
PS C:\>

Note that XoXo is displayed , ignoring my attempt to redefine it from the inside.

So is this possible?

+4
1

RTFM, . . MSBuild, , :

MSBuild /property (/p). , . , , .

, "" MSBuild

TreatAsLocalProperty , .

Project, , .

, :

<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         TreatAsLocalProperty="OutDir">

, OutDir . , , , -, TFS . , OutDir , . , , . :

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Try import if this file exists, it should supply the value for CustomOutDir-->
  <Import Project="$(MSBuildThisFileDirectory)customoutdir.props" Condition="Exists('$(MSBuildThisFileDirectory)customoutdir.props')"/>
  <PropertyGroup>
    <!-- Default value for CustomOutDir if not set elsewhere -->
    <CustomOutDir Condition="'$(CustomOutDir)' == ''">$(MSBuildThisFileDirectory)bin\$(Configuration)</CustomOutDir>
    <!-- ApplyCustomOutDir specifies whether or not to apply CustomOutDir -->
    <ActualOutDir Condition="'$(ApplyCustomOutDir)' == 'True'">$(CustomOutDir)</ActualOutDir>
    <ActualOutDir Condition="'$(ApplyCustomOutDir)' != 'True'">$(OutDir)</ActualOutDir>
  </PropertyGroup>
  <Target Name="Build">
    <MSBuild Projects="$(MasterProject)" Properties="OutDir=$(ActualOutDir)"/>
  </Target>
</Project>

,

msbuild stub.targets /p:MasterProject=/path/to/main.vcxproj;ApplyCustomOutDir=True

( TFS, )

+2

Source: https://habr.com/ru/post/1615851/


All Articles