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
  • 64,767
  • 30
  • 146
  • 239
Alex
  • 4,821
  • 16
  • 65
  • 106

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
  • 64,767
  • 30
  • 146
  • 239