visual-studio 如何自动将现有项目添加到 Visual Studio 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1743432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:13:45  来源:igfitidea点击:

How can I automatically add existing items to a Visual Studio project?

visual-studiovisual-studio-2008code-generation

提问by Edward Tanguay

I have a tool which dynamicallygenerates.xaml and .xaml.cs files and puts them in the appropriate Visual Studio directory.

我有一个工具可以动态生成.xaml 和 .xaml.cs 文件并将它们放在适当的 Visual Studio目录中

To addthem to the project, I have to then:

要将它们添加到项目中,我必须:

  • right-click on that directory
  • choose "add existing item"
  • navigate to the matching directory on the hard drive
  • select the two files that were created
  • click ok
  • 右键单击该目录
  • 选择“添加现有项目”
  • 导航到硬盘驱动器上的匹配目录
  • 选择创建的两个文件
  • 单击确定

Is there a way for me to tell the project to "include all existing items under the project folder on the hard drive"?

有没有办法让我告诉项目“包括硬盘驱动器上项目文件夹下的所有现有项目”?

回答by Maslow

You can do this programatically in your .projfile depending on your needs just like this answer

您可以.proj根据需要在文件中以编程方式执行此操作,就像这个答案一样

You just have to make sure you use the correct tag for the files.

您只需要确保为文件使用正确的标签。

Compile, Content, None, etc..

编译、内容、无等。

<ItemGroup>
  <Content Include="Images\**\*.*" />
  <Compile Include="Subdirectory\**\*.cs" />
</ItemGroup>

回答by Saar

I do not have any automation for this. Still I follow following for the same requirement. This will avoid few clicking.

我没有任何自动化。我仍然遵循相同的要求。这将避免很少点击。

  • In solution Explorer highlight/Select "Show all files" button
  • Press control key (to multi select) and select files with mouse click to be included in solution.
  • Right click on any one of highlighted file, and select "Include in project"
  • 在解决方案资源管理器中突出显示/选择“显示所有文件”按钮
  • 按控制键(多选)并通过鼠标单击选择要包含在解决方案中的文件。
  • 右键单击任何一个突出显示的文件,然后选择“包含在项目中”

回答by Dave Swersky

I don't think there is a way to do this natively in Visual Studio. Adding the files to the project modifies the project file.

我认为没有办法在 Visual Studio 中以本机方式执行此操作。将文件添加到项目会修改项目文件。

This sounds like a good case for a simple addin. You can use the Visual Studio automation services to find the files you want added and add them all at once. You'd have complete control over the behavior of the addin, so you could reduce the process to a single click if practical.

对于一个简单的插件来说,这听起来是一个很好的例子。您可以使用 Visual Studio 自动化服务来查找要添加的文件并一次性添加所有文件。您可以完全控制插件的行为,因此如果可行,您可以将过程减少到单击一次。