roslyn

TextTransform on MSBuild only when file modified? (or an alternate route of doing this)

南楼画角 提交于 2020-01-05 13:08:59
问题 I have a project that integrates TextTransform with MSBuild, but I am now at the point that the files are too many and it is slowing down development time. The process that I have is, I have a POCO.cs; I use Roslyn to Parse the .cs file to gather some metadata; hand the metadata to a .tt file that will then generate a [Implementation].cs Here is part of the .csproj file that pertains to my question: <PropertyGroup> <_CommonProgramFiles>$([System.Environment]::GetEnvironmentVariable(

Why does a Roslyn compilation include metadata references or project references but not both?

♀尐吖头ヾ 提交于 2020-01-05 12:59:34
问题 I'm using Roslyn to look at a project that references a number of System assemblies, like this: var workspace = MSBuildWorkspace.Create(); _solution = workspace.OpenSolutionAsync(_solutionPath).Result; var project = _solution.Projects.Single(p => p.Name == "TestProject"); When I look at project.MetadataReferences it has 9 elements and project.ProjectReferences has no elements - all as I'd expect. The Documents property contains one more document than I'd expect, a generated document. If I add

.NET Compiler Platform: Not Working

限于喜欢 提交于 2020-01-05 05:52:24
问题 I have Microsoft Visual Studio Enterprise 2017 Version 15.5.5 installed (latest version of the date apparently). However, I can't use .NET Compiler Platform SDK. I used to have it as an extension and now it just doesn't work with a warning. The warning says: "This extension is disabled because the installed version is incompatible with Visual Studio. Please go to the Updates tab to get the latest version of this extension to enable it". There's nothing on the Updates tab. Any idea how I could

Type or namespace 'MSBuild' does not exist in namespace 'Microsoft.CodeAnalysis' despite being able to navigate to definition

佐手、 提交于 2020-01-04 14:20:33
问题 I'm trying out Roslyn for the first time and I'm writing a small piece of code to read through a project, classes and class members. I'm using the MSBuildWorkspace class to create the Roslyn workspace ( MSBuildWorkspace.Create() ). Below is a small part of the code I've written using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.MSBuild; //Some problem in this line? Read on. ... ... var workspace = MSBuildWorkspace.Create(); Solution solutionToAnalyze = workspace.OpenSolutionAsync

VSIX: Adding Projects with Roslyn refactoring options says “Not supported”

强颜欢笑 提交于 2020-01-04 09:16:08
问题 I feel like there should be an easy way to do this. I mean it can't be possible that you can't add projects via extensions? What I want to do: I want to write a small extension that adds a "code refactoring" option to methods that will generate a test class and method for it in the matching test project. If the test project does not exist, I will create it. Everything is working so far, except that when I try to use Solution.AddProject() it throws the exception System.NotSupportedException :

How will Roslyn help me in avoiding a recompile to deploy changes to my ASP.NET website?

给你一囗甜甜゛ 提交于 2020-01-04 06:44:15
问题 I am a little confused about the new Roslyn C# compiler. In the beginning I assumed that this new compiler would make it possible to make changes to C# code in my ASP.NET MVC web site, and afterwards see these changes in a browser without ever have to rebuild the project/solution. However doing some more reading, especially the new information, I am now so sure any more. Is it possible, using Roslyn, to make changes to C# code within e.g. controller class and not having to build the project

Is it possible to detect unreachable code or other built in compile warnings using Roslyn

*爱你&永不变心* 提交于 2020-01-04 03:44:27
问题 Is it possible to detect unreachable code or other built in compile warnings using Roslyn? private void DoSomething() { string a = "TEST"; throw new Exception("Why would I throw an exception here?"); a = "This will never be reached"; //this is a compile time warning for unreachable code...Can I detect it? } I've tried examining the node properties in Semantic and Syntax methods but didn't see any issues or warning collections. 回答1: You can discover this using the semantic model's

References in Roslyn .rsp files

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 10:46:48
问题 I see in the CSharpInteractive.rsp you can add a reference to a DLL in the GAC using /r: How do you add references to your own DLLs? I tried System.Reflection.Assembly.LoadFrom, it didn't fail but didn't work. I am trying to add a reference to my DLL that has extension methods. If I try to add the code for the extension method directly in the interactive window I get this error: error CS1109: Extension methods must be defined in a top level static class; XYZ is a nested class 回答1: You should

Visit and modify all documents in a solution using Roslyn

萝らか妹 提交于 2020-01-03 08:37:34
问题 I want to walk over all the documents in every project in a given solution using Roslyn. This is the code I have now: var msWorkspace = MSBuildWorkspace.Create(); var solution = await msWorkspace.OpenSolutionAsync(solutionPath); foreach (var project in solution.Projects) { foreach (var document in project.Documents) { if (document.SourceCodeKind != SourceCodeKind.Regular) continue; var doc = document; foreach (var rewriter in rewriters) { doc = await rewriter.Rewrite(doc); } if (doc !=

How to find the SyntaxNode for a method Symbol in a CompilationUnit?

扶醉桌前 提交于 2020-01-03 07:28:28
问题 I've added a bunch of nodes to a compilation unit, and now I would like to look up the syntax node corresponding to a given symbol: var compilation = Compilation.Create("HelloWorld") .AddSyntaxTrees(SyntaxTree.ParseCompilationUnit("<some namespace>")); ISymbol symbol = // some arbitrary symbol, e.g. a method whose syntax node I had compilation.GlobalNamespace.GetNamespaceMembers().First(); SyntaxToken token = ???; // how do I get the token for that symbol? How do I get the token for that