简体   繁体   中英

Adding c# code to existing .net core project with Roslyn

Is it possible to load an existing .NET core project with Roslyn API, add a c# class and save it so the file is actually created on disk and added to the project. I tried to do it with MSBuildWorkspace and AddDocument and TryApplyChanges method - I can load the solution and project but the file is not created (and I don't get any exception or error).

Where can I find a working example that shows how to use Roslyn to accomplish something like that

The MSBuildWorkspace does not implement any of the 'add' functionality. It should be thought of as a 'read-only' view of the solution and its code.

AdhocWorkspace does allow adding and removing projects and documents, but it does not have some of the same capabilities as MSBuildWorkspace (AdhocWorkspace cannot handle Xaml files for example).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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