HintPath vs ReferencePath in Visual Studio(Visual Studio 中的 HintPath 与 ReferencePath)
问题描述
.csproj 文件中的 HintPath
和 .csproj.user
文件中的 ReferencePath
到底有什么区别?我们正在尝试遵守一个约定,其中依赖 DLL 位于发布"svn repo 中,并且所有项目都指向特定版本.由于不同的开发者有不同的文件夹结构,相对引用不起作用,所以我们想出了一个方案,使用一个指向特定开发者的发布文件夹的环境变量来创建一个绝对引用.所以添加引用后,我们手动编辑工程文件,使用环境变量将引用改为绝对路径.
What exactly is the difference between the HintPath
in a .csproj file and the ReferencePath
in a .csproj.user
file? We're trying to commit to a convention where dependency DLLs are in a "releases" svn repo and all projects point to a particular release. Since different developers have different folder structures, relative references won't work, so we came up with a scheme to use an environment variable pointing to the particular developer's releases folder to create an absolute reference. So after a reference is added, we manually edit the project file to change the reference to an absolute path using the environment variable.
我注意到这可以通过 HintPath
和 ReferencePath
来完成,但我发现它们之间的唯一区别是 HintPath
在构建时解析,ReferencePath
在项目加载到 IDE 时解析.我不太确定这样做的后果是什么.我注意到VS有时会重写.csproj.user
,我必须重写ReferencePath
,但我不确定是什么触发了.
I've noticed that this can be done with both the HintPath
and the ReferencePath
, but the only difference I could find between them is that HintPath
is resolved at build-time and ReferencePath
when the project is loaded into the IDE. I'm not really sure what the ramifications of that are though. I have noticed that VS sometimes rewrites the .csproj.user
and I have to rewrite the ReferencePath
, but I'm not sure what triggers that.
我听说最好不要签入 .csproj.user
文件,因为它是特定于用户的,所以我想以此为目标,但我也听说过如果相同的 DLL 例如位于项目的输出目录中.对此有什么想法吗?
I've heard that it's best not to check in the .csproj.user
file since it's user-specific, so I'd like to aim for that, but I've also heard that the HintPath
-specified DLL isn't "guaranteed" to be loaded if the same DLL is e.g. located in the project's output directory. Any thoughts on this?
推荐答案
根据这个 MSDN 博客:https://blogs.msdn.microsoft.com/manishagarwal/2005/09/28/resolving-file-references-in-team-build-part-2/
According to this MSDN blog: https://blogs.msdn.microsoft.com/manishagarwal/2005/09/28/resolving-file-references-in-team-build-part-2/
在构建时有一个程序集的搜索顺序.搜索顺序如下:
There is a search order for assemblies when building. The search order is as follows:
- 来自当前项目的文件 - 由 ${CandidateAssemblyFiles} 表示.
- 来自 .user/targets 文件的 $(ReferencePath) 属性.
- %(HintPath) 元数据由参考项指示.
- 目标框架目录.
- 在注册表中找到使用 AssemblyFoldersEx 注册的目录.
- 注册的程序集文件夹,由 ${AssemblyFolders} 表示.
- $(OutputPath) 或 $(OutDir)
- 广汽
因此,如果 HintPath 找到了所需的程序集,但可以使用 ReferencePath 找到替代程序集,则它将更喜欢 ReferencePath'd 组装到 HintPath'd 一个.
So, if the desired assembly is found by HintPath, but an alternate assembly can be found using ReferencePath, it will prefer the ReferencePath'd assembly to the HintPath'd one.
这篇关于Visual Studio 中的 HintPath 与 ReferencePath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Visual Studio 中的 HintPath 与 ReferencePath
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30