【问题标题】:MSBuild ignores OutDir and always forces rebuildMSBuild 忽略 OutDir 并始终强制重建
【发布时间】:2014-08-22 07:51:18
【问题描述】:

我们的解决方案包含约 50 个项目。它们都导入了一个自定义的 .target 文件,该文件设置了 OutDir 变量,以便所有项目都构建到一个通用的 Binaries 文件夹中。

问题是:MSBuild 不会检查 OutDir 文件夹中的 .dll,但会一直查看 OutputPath 文件夹(例如 bin\Debug)。由于 OutputPath 文件夹为空,它表明每个项目都不是最新的并强制重建。这在我们的 TFS 构建代理上不是问题,但它大大增加了按下 F5 和应用程序在我们的开发机器上启动之间的时间。调试变得相当痛苦。

Binaries 文件夹中,我们将 .dll 复制到我们用于生成设置等的应用程序文件夹结构中。因此简单地放弃使用 OutDir 以支持各种OutputPaths 不是一个选项。

有没有办法告诉 MSBuild 在查找现有 .dll 时也检查 OutDir 文件夹?

【问题讨论】:

  • 你有没有想过这个问题?
  • @StevenLiekens 不是真的。我们手动修改了每个 *.csproj 文件以匹配最后的 OutDir 路径。
  • 我现在正在跳 OutDirOutputPath 的舞蹈。只要我在导入 Microsoft.CSharp.targets 之前设置属性,它似乎至少可以部分工作。

标签: visual-studio-2012 msbuild rebuild outdir


【解决方案1】:

在 VS 2015 中导入 csproj 文件对我有用。我添加了有关哪些设置使其失败的 cmets:

   <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

      <PropertyGroup>
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
        <!-- to distinguish by $(Platform) does not work, a rebuild is triggered since the up-to-date check fails -->
        <!-- if IntermediateOutputPath is not set here at all, it does not work either, i.e. it always rebuilds -->
        <IntermediateOutputPath>$(SolutionDir)obj\$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath>
        <UseCommonOutputDirectory>False</UseCommonOutputDirectory>
        <DisableFastUpToDateCheck>false</DisableFastUpToDateCheck>
      </PropertyGroup>

      <PropertyGroup Condition=" '$(OutputType)' == 'Library' ">
        <!-- To distinguish by \lib\ does not work, a rebuild is triggered since the up-to-date check fails -->
        <!-- <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\lib\</OutputPath> -->
        <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)</OutputPath>   
        <OutDir>$(OutputPath)</OutDir>
      </PropertyGroup>

      <PropertyGroup Condition=" '$(OutputType)' == 'Exe' ">
        <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\</OutputPath>
        <OutDir>$(OutputPath)</OutDir>
      </PropertyGroup>
    </Project>

该文件包含在导入 Microsoft.CSharp.targets 之前的 csproj 文件中:

.csproj 文件:

<!-- position of include is important, OutputType of project must be defined already -->
<Import Project="$(SolutionDir)ComponentBuild.props" Condition="Exists('$(SolutionDir)ComponentBuild.props')" /> 
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
  <PostBuildEvent>
  </PostBuildEvent>
</PropertyGroup>

另请参阅我自己的 SO 问题: MSBuild, OutputPath to a lib directory is not honoured

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多