[英]How add existing project to c# solution with roslyn?
I want to add an existing project to my c# solution.I used TryApplyChanges and it returns true but it doesn't save changes to real Solution. 我想将现有项目添加到我的C#解决方案中。我使用了TryApplyChanges,它返回true,但不会将更改保存到实际的Solution中。 I used Microsoft.CodeAnalysis.* version 1.1.1. 我使用的是Microsoft.CodeAnalysis。*版本1.1.1。
public void AddProject (string solutionName)
{
MSBuildWorkspace ws=MSBuildWorkspace.Create ();
ws.OpenSolutionAsync (solutionName);
ws.OpenProjectAsync ("ProjectName");
if (ws.TryApplyChanges (ws.CurrentSolution )
{// break point is here
}
}
There's a few problems with your code: 您的代码存在一些问题:
MSBuildWorkspace
doesn't (currently) support adding/or removing projects from the workspace and saving them back to the solution file. MSBuildWorkspace
不(当前)支持在工作空间中添加/删除项目并将其保存回解决方案文件中。 We're open source if you want to look into improving this. 如果您想对此进行改进, 我们是开源的 。 The first is obviously the most critical for you, but the others should be noted too. 对于您来说,第一个显然是最关键的,但其他一些也应注意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.