哪一个是在csproj文件中进行程序集引用的正确方法? [英] Which one is correct approach for assembly reference in csproj file?

查看:338
本文介绍了哪一个是在csproj文件中进行程序集引用的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个MSI安装程序中,我正在按程序更新程序集和项目引用的相对路径。我的所有引用程序集都放在应用程序文件夹中。

In my one of the MSI Installer I am updating the assembly and project reference relative path pro-grammatically.My all reference assemblies inside my application folder.

我尝试同时实现相对路径和绝对路径。

I try to implement both the path relative and absolute path. Both are working fine.

相对路径

 <Reference Include="log4net">
      <HintPath>..\..\..\..\log4net.dll</HintPath>
 </Reference>

绝对路径

 <Reference Include="log4net">
          <HintPath>C:\Program files\Myapplication\log4net.dll</HintPath>
 </Reference>

当我从参考装配体路径或GAC中获取装配体参考时,我仅看到了绝对路径参考

I have only seen absolute path reference when I take the reference of assembly from the Reference Assemblies Path or GAC files.

C:\Program Files (x86)\Reference Assemblies

 <Reference Include="System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll</HintPath>
    </Reference>

哪个是将路径更新为的正确方法。Csproj文件?

Which one is correct approach for updating path into .Csproj file?

推荐答案

如您所说:两者都能正常工作。

As you stated: Both work fine.

在某些极端情况下,实际上您在 .csproj 文件中使用相对路径还是绝对路径很重要:

There are corner cases, where it in fact does matter if you're using relative or absolute paths in your .csproj file:


  • 当您计划移动 .csproj 文件时。引用的程序集也会移动,然后移动到相对路径,否则走绝对路径。

  • 当文件夹结构中存在极端嵌套时,相对路径可能会超过260个字符的路径名限制。这是因为完整路径是在内部通过简单地连接项目目录路径和相对路径(包括所有 .. \ )建立的。然后,串联的路径可能会超出上面提到的路径名限制,而绝对路径不会超过。

  • When you plan to move your .csproj file. Will the referenced assemblies move also, then go for relative paths, otherwise take absolute paths.
  • When you have extreme nesting in your folder structure, then a relative path might exceed the 260 characters path name limit. This is since the full path is built internally by simply concatenating the project directory path and the relative path (including all the ..\). The concatenated path then might exceed the characters-in-path-name-limit mentioned above whereas the absolute path does not.

这篇关于哪一个是在csproj文件中进行程序集引用的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆