4

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?

Saroop Trivedi
  • 2,245
  • 6
  • 31
  • 49

1 Answers1

2

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.
The Chairman
  • 7,087
  • 2
  • 36
  • 44
  • 4
    It looks like Visual Studio accepts an environment variable, so you can say `$(ProgramFiles)\Myapplication\log4net.dll` if you want the absolute path. The advantage is that if the folder name is localized (which it is in non-English versions of Windows) or does contain the `(x86)` suffix, it should still work. However, I don't know if other tools than Visual Studio are OK with environment variables in the hint path. – Jeppe Stig Nielsen Dec 14 '12 at 12:58