问题
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