Which one is correct approach for assembly reference in csproj file?

久未见 提交于 2020-01-03 17:20:54

问题


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.

Relative Path

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

Absolute path

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

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>

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


回答1:


As you stated: Both work fine.

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

  • 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.


来源:https://stackoverflow.com/questions/11108838/which-one-is-correct-approach-for-assembly-reference-in-csproj-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!