We are using Roslyn code to autogenerate some .cs file in an asp.net core mvc
project using Visual Studio 2017 15.4
After some recent changes to the branch I am getting this error
Type: System.InvalidOperationException Message: Cannot modify an evaluated object originating in an imported file "C:\Program Files\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.props". Stack: at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(StringresourceName, Object[] args) at Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInvalidOperation(Boolean condition, String resourceName, Object arg0) at Microsoft.Build.Evaluation.Project.VerifyThrowInvalidOperationNotImported(ProjectRootElement otherXml) at Microsoft.Build.Evaluation.Project.RemoveItemHelper(ProjectItem item) at Microsoft.Build.Evaluation.Project.RemoveItem(ProjectItem item)
at Microsoft.CodeAnalysis.MSBuild.ProjectFile.RemoveDocument(String filePath)at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.ApplyDocumentRemoved(DocumentId documentId) at Microsoft.CodeAnalysis.Workspace.ApplyProjectChanges(ProjectChanges projectChanges) at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.ApplyProjectChanges(ProjectChanges projectChanges) at Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker) at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker)
try
{
var solutionPath = dataAccessGeneratorConfig.Solution;
using (var workspace = MSBuildWorkspace.Create())
{
var solution = workspace.OpenSolutionAsync(solutionPath).Result;
foreach (var dataAccessSource in dataAccessGeneratorConfig.DataSources)
{
// Add/remove documents to the project
}
workspace.TryApplyChanges(solution);
workspace.CloseSolution();
}
catch (Exception ex)
{
// Exception Handling
}
I have consulted other such thread and the github page but it doesn't help. Any clues?