2

How do we include a file in a project using code?

I want to include this file:

File to include

I also want the equivalent of this:

Include

In code ... Is it possible?

ThinkingStiff
  • 63,812
  • 29
  • 142
  • 238
Alex
  • 4,631
  • 16
  • 64
  • 105

1 Answers1

5

You can do this a few ways.

Command Line:

devenv /command "File.AddExistingSolutionItem fullpath\filename"

Project File:

The project file is XML. You can open and modify it like any file.

Code:

Use Microsoft.Build.Evaluation.Project to inspect and modify project files. The .AddItem() method is what you're looking for.

Community
  • 1
  • 1
ThinkingStiff
  • 63,812
  • 29
  • 142
  • 238