我正在尝试通过添加以下内容来设置我的csproj文件以在父目录中搜索依赖项:
<PropertyGroup>
<AssemblySearchPaths>
..\Dependencies\VS2012TestAssemblies\; $(AssemblySearchPaths)
</AssemblySearchPaths>
</PropertyGroup>
我将此添加为最后一个PropertyGroup元素,紧接在具有所有Reference声明的第一个ItemGroup之前。
不幸的是,这导致所有其他引用都无法解析,例如:
ResolveAssemblyReferences:
Primary reference "Microsoft.CSharp".
9>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.CSharp". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
For SearchPath "..\Dependencies\VS2012TestAssemblies\".
Considered "..\Dependencies\VS2012TestAssemblies\Microsoft.CSharp.winmd", but it didn't exist.
Considered "..\Dependencies\VS2012TestAssemblies\Microsoft.CSharp.dll", but it didn't exist.
Considered "..\Dependencies\VS2012TestAssemblies\Microsoft.CSharp.exe", but it didn't exist.
有没有一种简单的方法可以告诉msbuild在哪里搜索项目的依赖项?我知道我可以使用/p:ReferencePath,但是我更喜欢在csproj文件本身中包含编译逻辑,而不是让TFS Team Build指示要查找的位置,更不用说我希望它能够在其他版本上进行编译开发人员机器。
我确实尝试将$(AssemblySearchPaths)移到列表的第一位,但这没有帮助。
最佳答案
您可以在目标“BeforeResolveReferences”内更改“AssemblySearchPaths”属性的值,看看是否可以解决您的问题?
<Target Name="BeforeResolveReferences">
<CreateProperty
Value="..\Dependencies\VS2012TestAssemblies;$(AssemblySearchPaths)">
<Output TaskParameter="Value"
PropertyName="AssemblySearchPaths" />
</CreateProperty>
</Target>