问题
How do we include a file in a project using code?
I want to include this file:

I also want the equivalent of this:

In code ... Is it possible?
回答1:
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.
来源:https://stackoverflow.com/questions/15180527/include-in-project-programmatically