繁体   English   中英

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

[英]How to add files to the build (.csproj) file dynamically

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

条件:它需要在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();
}

帮助任何人?

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

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

其他一样

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM