如何动态地将文件添加到构建(.csproj)文件

时间:2014-06-18 07:29:14

标签: c# msbuild

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

标准:它需要在visual studio中工作,它需要在独立构建中工作

// 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();
}

帮助任何人?

1 个答案:

答案 0 :(得分:0)

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

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

其他

相同
相关问题