C# 如何向生成(.csproj)文件动态添加文件

C# 如何向生成(.csproj)文件动态添加文件,c#,msbuild,C#,Msbuild,当客户创建一个新的工作区时,我生成了一堆文件,我想将它们添加到现有的项目文件中,最好的方法是什么 标准:它需要在VisualStudio中工作,并且需要在独立构建中工作 // get the project file ... var projectfile = Directory.GetFiles(Requested.Workspace.AppRoot, "*.csproj", SearchOption.AllDirectories).Single(); var project = new Pr

当客户创建一个新的工作区时,我生成了一堆文件,我想将它们添加到现有的项目文件中,最好的方法是什么

标准:它需要在VisualStudio中工作,并且需要在独立构建中工作

// get the project file ...
var projectfile = Directory.GetFiles(Requested.Workspace.AppRoot, "*.csproj", SearchOption.AllDirectories).Single();
var project = new Project(projectfile);

// add generated items ...
foreach (var item in Requested.Manifest.Items)
{
   project.Items.Add(new ProjectItem(item.Info.FullName,"??"));
}

if (!project.Build())
{
   Console.ReadLine();
}

帮助任何人?

您可以创建一个.cs文件,将所有填充内容作为方法添加到其中,并根据工作区调用特定函数

If(workspace 1)
{
// call file1Method()
}

其他的也一样

uhh什么??对不起,我不明白。你能详细说明一下吗?你可以使用
EnvDTE.dll
。更多信息,我独立于visual studio生成文件,因此我没有可用的EnvDTE。也许我在这里的回答可以帮助您:是的,如果它没有标记为obselete,并且在新的生成引擎中没有替换,那么它会起作用