roslyn

Strange diagnostics errors, prefedined type System… is not defined or imported

寵の児 提交于 2019-12-01 12:04:18
I am getting Roslyn diagnostics errors when parsing a very basic .NET 4.6 application. The solution files can be downloaded from there https://github.com/dotnet/roslyn/files/2393288/DemoSolution.zip The dependency tree looks like this: BLL -> DB I am getting the following diagnostics errors in the BLL project: The solution and projects build fine, still Roslyn gives these errors. Maybe the errors are misleading and I need to configure the projects in someway? Any idea how I can resolve these errors? Here is the code used for parsing the files: var properties = new Dictionary<string, string> {

How can I get the fully qualified namespace from a using directive in Roslyn?

自闭症网瘾萝莉.ら 提交于 2019-12-01 10:43:39
When you hover over a "simplified" using directive in VS2015, it shows you the fully-qualified name. How would I get this information via a Roslyn plugin? Would it be using a DiagnosticAnalyzer ? A CodeFixProvider ? Reading through source.roslyn.codeplex.com, there's tons of information there, including how to add a using statement , and also how to simplify type names (including using statements), but I'm unable to figure out how to go in reverse to get the fully-qualified name. With the semantic model you can retrieve information about the semantics that make up your code (evidently) -- this

Roslyn: How to get a reference to Workspace from currently loaded solution?

旧巷老猫 提交于 2019-12-01 09:22:23
I am trying to get a reference to currently loaded workspace, without success. As per documentation (part in bold) I should be able to get a reference to it. The Workspace APIs are found in the Roslyn.Services namespace, and they are available if you include the following using directive: using Roslyn.Services; The workspace you use will typically be provided directly by the host environment (such as the Visual Studio IDE) . However, you can work with a workspace outside of a host environment by constructing your own IWorkspace instance. You can construct a workspace by loading a solution file

Get type information for type declared in another assembly/project

橙三吉。 提交于 2019-12-01 08:55:55
问题 So as the title says I'm trying to get type information from types declared in another assembly using Roslyn. Initially I tried to do this by manually looking through referenced assemblies but realised I didn't have namespace information. I was expecting the below to work: var workSpace = Roslyn.Services.Workspace.LoadSolution(solFilePath); IDocument file = null; IProject proje = null; Compilation compilation = Compilation.Create("Test"); List<CommonSyntaxTree> trees = new List

Roslyn - replace node and fix the whitespaces

为君一笑 提交于 2019-12-01 06:54:53
In my program I use Roslyn and I need to replace a node with a new node. For example, if I have code like public void Foo() { for(var i = 0; i < 5; i++) Console.WriteLine(""); } and I want to insert brackes for for statement, I get public void Foo() { for(var i = 0; i < 5; i++) { Console.WriteLine(""); } } I tried to use NormalizeWhitespace, but if I use it on for statement, I get public void Foo() { for(var i = 0; i < 5; i++) { Console.WriteLine(""); } } However, I'd like to have for statement formatted correctly. Any hints how to do it? EDIT: I solved it by using: var blockSyntax =

Embedding C# sources in PDB with new csproj

旧城冷巷雨未停 提交于 2019-12-01 06:52:54
The recently-released .NET tooling seem to have support for embedding C# in PDBs , which should improve the experience of stepping into third-party, etc. Running csc /? , I can clearly see the /embed option: "Embed all source files in the PDB." However, there doesn't seem to be any way to specify this in csproj. What's more, there doesn't seem to be any provisions for passing arbitrary switches to the compiler, which I would use to manually pass /embed. Can anyone confirm that I haven't missed anything and that build support for /embed is currently lacking? Is there an issue for this (and if

Roslyn: How to get a reference to Workspace from currently loaded solution?

南楼画角 提交于 2019-12-01 06:44:37
问题 I am trying to get a reference to currently loaded workspace, without success. As per documentation (part in bold) I should be able to get a reference to it. The Workspace APIs are found in the Roslyn.Services namespace, and they are available if you include the following using directive: using Roslyn.Services; The workspace you use will typically be provided directly by the host environment (such as the Visual Studio IDE) . However, you can work with a workspace outside of a host environment

Is there any way to get Members of a type and all subsequent base types?

↘锁芯ラ 提交于 2019-12-01 06:33:24
I have an ` ITypeSymbol ' object. If I call GetMembers , it gives me the members of the current type, not the base. I know I can dig it using BaseType property and have some iterative code to fetch all the properties. Is there any easier way to fetch all members regardless of level at the inheritance hierarchy? JoshVarty If you're looking for all members whether or not they're accessible: There is no public API to do this, and internally the Roslyn team's approach is more or less the same as what you've described. Take a look at the internal extension method GetBaseTypesAndThis() . You could

'Main' method not found when compiling through Roslyn

有些话、适合烂在心里 提交于 2019-12-01 06:18:40
I am using Roslyn to compile a solution with run-time generated code. While the solution compiles perfectly when opened from Visual Studio, it fails from Roslyn: error CS5001: Program does not contain a static 'Main' method suitable for an entry point The solution I am trying to compile has a single ASP.NET Core 2 (.NET Framework 4.6.2) project, which of course has a Main method in the Program class at the root of the project: public class Program { public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory())

Embedding C# sources in PDB with new csproj

耗尽温柔 提交于 2019-12-01 06:06:21
问题 The recently-released .NET tooling seem to have support for embedding C# in PDBs, which should improve the experience of stepping into third-party, etc. Running csc /? , I can clearly see the /embed option: "Embed all source files in the PDB." However, there doesn't seem to be any way to specify this in csproj. What's more, there doesn't seem to be any provisions for passing arbitrary switches to the compiler, which I would use to manually pass /embed. Can anyone confirm that I haven't missed