以编程方式包括在项目中 [英] Include in project programmatically

查看:135
本文介绍了以编程方式包括在项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何使用代码将文件包含在项目中?

我要包含此文件:

我也想要这样的东西:

用代码...有可能吗?

解决方案

您可以通过几种方法来实现.

命令行:

devenv/命令"File.AddExistingSolutionItem fullpath \ filename"

项目文件:

项目文件是XML.您可以像打开任何文件一样打开和修改它.

代码:

使用Microsoft.Build.Evaluation.Project检查和修改项目文件. .AddItem()方法就是您要寻找的.

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?

解决方案

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.

这篇关于以编程方式包括在项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆