Include in project programmatically

2019-07-18 10:28发布

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?

1条回答
爷的心禁止访问
2楼-- · 2019-07-18 10:48

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.

查看更多
登录 后发表回答