Msbuild 如何从相应的csproj文件中忽略命令行上给定的属性值?

Msbuild 如何从相应的csproj文件中忽略命令行上给定的属性值?,msbuild,Msbuild,我们的TFS构建控制器将来自同一解决方案的所有项目构建到同一个共享bin目录中,因为TFS构建工作流将OutDir参数传递给负责构建解决方案的msbuild命令 我有一个项目,我想抑制这种行为,让它构建到标准的相对bin\Debug或bin\Release目录中 但是我找不到怎么做。实际上,请遵守以下简单的msbuild脚本: <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultT

我们的TFS构建控制器将来自同一解决方案的所有项目构建到同一个共享bin目录中,因为TFS构建工作流将
OutDir
参数传递给负责构建解决方案的msbuild命令

我有一个项目,我想抑制这种行为,让它构建到标准的相对
bin\Debug
bin\Release
目录中

但是我找不到怎么做。实际上,请遵守以下简单的msbuild脚本:

<?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>
请注意,它显示了XoXo,忽略了我从内部重写它的尝试


那么,有可能吗

这是一个有点经典的RTFM情况,但仍然很有趣。请参阅文档,特别是上的部分以及如何使属性不被前者覆盖:

MSBuild允许您使用/property(或/p)开关在命令行上设置属性。这些全局特性值将替代在项目文件中设置的特性值。这包括环境属性,但不包括不能更改的保留属性

还可以使用MSBuild任务的properties属性为多项目生成中的子项目设置或修改全局属性

如果使用TreatAsLocalProperty属性指定属性 在项目标记中,该全局属性值不会覆盖 在项目文件中设置的属性值

它还链接到基本上重复相同信息的元素文档,并表示属性中的多个属性应该用分号分隔

简而言之,适用于您的案例的代码:

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

(我从未使用过TFS,因此传递属性的方式可能会有所不同)

RTFM的谴责是当之无愧的,尽管我不确定我的阅读理解是否足够好,是否能够突破这一特定文档:-)。我正在为门控签入构建使用存根项目方法,但是CI构建在我之前就已经存在了,所以它就是这样工作的。非常感谢,非常有教育意义。您在文档中的观点是正确的:它不完全清楚,例如,如果从说“全球财产是……”开始可能会更好
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         TreatAsLocalProperty="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