Visual Studio: Using external files (without copying them)

11,906

Solution 1

You can add a source code file to a project as a link.

To do so:

  1. Right-click project and select "Add -> Existing Item"
  2. Navigate to the file you want to add as a link, and select it.
  3. Look at the "Add" button at lower right of the "Add Existing Item" dialog. It has a little drop arrow. Click that drop arrow.
  4. Select "Add as link".

Solution 2

Follow the setps:

  • Right click on the project go to Add
  • Select Existing Item
  • Select the file
  • On the Add button click the drop down button and select "Add as a Link"

enter image description here

Solution 3

Lets say I want to add a csv file to a project.

  • Right click on the directory in which you want to add.
  • Click on ADD and then Existing Item
  • Click on Add/Add as link , also if you are dealing with csv files or files which don't have convention extensions select All Files in that case.

Screen shot

Share:
11,906

Related videos on Youtube

K. D.
Author by

K. D.

Updated on June 07, 2022

Comments

  • K. D.
    K. D. almost 2 years

    I want to import an enum class (.cs) into my project that is generated by another service. So if that service will update this file, it should be automatically updated in my project. It has to be text-only (so I can't use an assembly) because we can't compile code in php.

    And here is why I want this: We are using global language strings in multiple applications and I would like to use them as enumerations for some reasons. When new texts are added I want to be able to use them without copying or changing anything. Maybe there is another way to achieve this.

    Thank you.

  • Zachary Kniebel
    Zachary Kniebel almost 10 years
    I don't think that's what he means - I think he wants the file to be linked so changing it in one place changes it for both
  • DLeh
    DLeh almost 10 years
    @ZacharyKniebel if you add the item as a link, this will happen.
  • Habib
    Habib almost 10 years
    @ZacharyKniebel, Adding it as a link would have the same effect
  • T.S.
    T.S. almost 10 years
    Honestly, adding file as link, must be not that different strategically from creating a separate library. Because if you have many projects and you modified this file from one project, you better go and rebuild all other projects that use this file.
  • cup
    cup almost 10 years
    Yes - that is exactly what I wanted. Now I'll have to go back to VS2003 to see if it had that feature. It has been bugging me for the last 12 years.
  • cup
    cup almost 10 years
    Just for info, the feature exists on all versions of VS from 2002 onwards.
  • phuclv
    phuclv about 5 years
    there's nothing new compared to the existing answers
  • NIshank
    NIshank about 5 years
    @phuclv I once had to add csv file to project. I wasted around 20-25 minutes to figure it out even after reading the answers. The file dragdown should be set to All Files instead of default in such case.
  • phuclv
    phuclv about 5 years
    did you see the image in the other answer? It clearly shows where you have to click
  • Hossein
    Hossein about 4 years
    Thanks a lot. this single image made my day.
  • matttm
    matttm over 3 years
    I see my sources in the explorer, but I cannot include them in the previously existing code. Right clicking them indicates that they are being included in the project.