当参数是字符串时,如何获取可能的字符串列表 [英] How to get list of possible strings when parameter is a string

查看:38
本文介绍了当参数是字符串时,如何获取可能的字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了以编程方式将文件包含到项目中,我使用此答案中提供的方法 https://stackoverflow.com/a/23537007/1317323

In order to programmatically include a file to a project I use the method provided in this answer https://stackoverflow.com/a/23537007/1317323

现在我需要更进一步,将xaml文件和xaml.cs文件添加到我的项目中.

Now I need to go further and add a xaml file and xaml.cs file to my project.

我需要知道在方法 AddItem()中可以接受的字符串,以便以正确的方式包含两个文件.像

I need to know what would be an accepted string in the method AddItem() in order to include both files the right way. Something like

p.AddItem("Page", "so.xaml");
// or
p.AddItem("Xaml", so.xaml");

当我使用经典的Visual Studio右键单击/添加新项目"的方式时,会在csproj文件中得到它

When I use the classic visual studio "right click/ add new item" way, I get this in the csproj file

<ItemGroup>
  <Page Include="example.xaml">
    <SubType>Designer</SubType>
    <Generator>MSBuild:Compile</Generator>
  </Page>
</ItemGroup>
<Compile Include="example.xaml.cs">
  <DependentUpon>example.xaml</DependentUpon>
</Compile>

我读过msdn没运气.

I read msdn with no luck.

我正在寻找一个表,该表将给定项类型的第一个参数或构造该表的方式赋予该值.

I'm loking for a table that would give the value a the first parameter for a given item type or a way to construct such a table.

推荐答案

我能够使用Microsoft的另一个名称空间来做到这一点.

I was able to do it using another namespace from Microsoft.

该解决方案基于一个

而不是用

 Microsoft.Build.Evaluation.Project

我用

Microsoft.VisualStudio.Shell.Interop

现在我可以操作

EnvDTE.Project

我可以使用

_currentProject.ProjectItems.AddFromFile(path);

如果我使用相同名称的xaml和xaml.cs文件执行两次,则会自动嵌套.

If I do it twice with a xaml and a xaml.cs file with the same name, there are automatically nested.

这篇关于当参数是字符串时,如何获取可能的字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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