msbuild - 在 csproj 文件中使用 AssemblySearchPaths

标签 msbuild dependency-management

我正在尝试通过添加以下内容来设置我的 csproj 文件以在父目录中搜索依赖项:

<PropertyGroup>
    <AssemblySearchPaths>
       ..\Dependencies\VS2012TestAssemblies\; $(AssemblySearchPaths)
   </AssemblySearchPaths>
</PropertyGroup>

我在第一个包含所有引用声明的 ItemGroup 之前添加了它作为最后一个 PropertyGroup 元素。

不幸的是,这导致所有其他引用无法解析,例如:
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 Builds 决定在哪里查看,更不用说我希望它能够在其他文件上编译开发者机器。

我确实尝试将 $(AssemblySearchPaths) 移到列表中的第一位,但这没有帮助。

最佳答案

您能否更改目标“BeforeResolveReferences”中“AssemblySearchPaths”属性的值,看看是否能解决您的问题?

    <Target Name="BeforeResolveReferences">
<CreateProperty
    Value="..\Dependencies\VS2012TestAssemblies;$(AssemblySearchPaths)">
    <Output TaskParameter="Value"
        PropertyName="AssemblySearchPaths" />
</CreateProperty>
</Target>

关于msbuild - 在 csproj 文件中使用 AssemblySearchPaths,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19309880/

相关文章:

delphi - 如何使用 Delphi 和 MSBuild 指定可执行文件的名称?

gradle - 什么时候两个工件被视为相等?

OCaml - 是否可以在沙丘中定义外部(系统)依赖项?

java - IntelliJ中使用的是哪个maven右键->maven->reimport

visual-studio - 如何为 Visual Studio 命令提示符创建批处理文件

.net - StyleCop 与 CI 构建过程(Cruise Control、Nant、msbuild 和 StyleCop)的集成

msbuild - 如何使用 MsBuild API 4.0 自动构建解决方案?

.net - 使用 AfterTargets 的 MSBuild 任务在转换后加密 web.config

python-3.x - 有没有办法将我的 python 应用程序与其所有依赖项捆绑在一起,以便我可以将它分发给普通用户?

python pycharm依赖同步