This project is read-only.
2
Vote

Adding reference of one project to another is not Working

description

Hi,

I have used the following code to add the project reference but it didn't work
       MSBuildWorkspace workspace = MSBuildWorkspace.Create();
        Microsoft.CodeAnalysis.Solution originalSolution =    workspace.OpenSolutionAsync(sol.SolutionPath).Result;
        Microsoft.CodeAnalysis.Solution newSolution = originalSolution;

        ProjectId pid = newSolution.Projects.First().Id;
        ProjectReference pr = new ProjectReference(pid);
        CodeAnalysis.Project prj = newSolution.Projects.Last();
        prj = prj.AddProjectReference(pr);
        newSolution = prj.Solution;

        workspace.TryApplyChanges(newSolution);

Please help me if possible i need this urgently

Regards
Rajesh Rai

comments

Pilchie wrote Dec 4, 2014 at 9:48 PM

Hi,

It's true that we don't currently support adding or removing project references in the MSBuildWorkspace. While we'd like to, it's probably not something that we will get to for a while.

In the meantime, you can see whether a given change is supported using the Workspace.CanApplyChange method.

If you want to persist these changes, you should look at modifying the xml of the project file yourself in the meantime.