簡體   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