查看文件 Microsoft.Common.targets
问题的答案在您的目标框架版本的文件Microsoft.Common.targets 中。
对于 .Net Framework 4.0 版(和 4.5 版!),AssemblySearchPaths 元素的定义如下:
<!--
The SearchPaths property is set to find assemblies in the following order:
(1) Files from current project - indicated by {CandidateAssemblyFiles}
(2) $(ReferencePath) - the reference path property, which comes from the .USER file.
(3) The hintpath from the referenced item itself, indicated by {HintPathFromItem}.
(4) The directory of MSBuild's "target" runtime from GetFrameworkPath.
The "target" runtime folder is the folder of the runtime that MSBuild is a part of.
(5) Registered assembly folders, indicated by {Registry:*,*,*}
(6) Legacy registered assembly folders, indicated by {AssemblyFolders}
(7) Resolve to the GAC.
(8) Treat the reference's Include as if it were a real file name.
(9) Look in the application's output folder (like bin\debug)
-->
<AssemblySearchPaths Condition=" '$(AssemblySearchPaths)' == ''">
{CandidateAssemblyFiles};
$(ReferencePath);
{HintPathFromItem};
{TargetFrameworkDirectory};
{Registry:$(FrameworkRegistryBase),$(TargetFrameworkVersion),$(AssemblyFoldersSuffix)$(AssemblyFoldersExConditions)};
{AssemblyFolders};
{GAC};
{RawFileName};
$(OutDir)
</AssemblySearchPaths>
.Net Framework 3.5 定义相同,但注释错误。 2.0 的定义略有不同,它使用 $(OutputPath) 而不是 $(OutDir)。
在我的机器上,我有以下版本的 Microsoft.Common.targets 文件:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets
C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Microsoft.Common.targets
C:\Windows\Microsoft.NET\Framework64\v3.5\Microsoft.Common.targets
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets
这适用于在 Windows 7 上安装的 Visual Studio 2008、2010 和 2013。
搜索输出目录的事实可能有点令人沮丧(正如原始海报指出的那样),因为它可能隐藏了不正确的 HintPath。该解决方案可以在您的本地机器上构建,但是当您在干净的文件夹结构中构建时(例如在构建机器上)会中断。