27

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.

K. D.
  • 4,041
  • 9
  • 48
  • 72

3 Answers3

49

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".
Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
  • 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. – matttm Oct 20 '20 at 11:48
18

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

Habib
  • 219,104
  • 29
  • 407
  • 436
  • 1
    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 – Zachary Kniebel Jun 19 '14 at 16:05
  • 1
    @ZacharyKniebel if you add the item as a link, this will happen. – DLeh Jun 19 '14 at 16:05
  • 1
    @ZacharyKniebel, Adding it as a link would have the same effect – Habib Jun 19 '14 at 16:06
  • 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. – T.S. Jun 19 '14 at 16:11
  • 1
    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 Jun 19 '14 at 16:16
  • 1
    Just for info, the feature exists on all versions of VS from 2002 onwards. – cup Jun 19 '14 at 16:53
2

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

phuclv
  • 37,963
  • 15
  • 156
  • 475
NIshank
  • 97
  • 6
  • 2
    there's nothing new compared to the existing answers – phuclv Mar 28 '19 at 04:43
  • @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. – NIshank Mar 28 '19 at 06:54
  • 1
    did you see the image in the other answer? It clearly shows where you have to click – phuclv Mar 28 '19 at 06:57
  • Thanks a lot. this single image made my day. – Hossein Apr 13 '20 at 10:27