roslyn

Project MetadataReferences is not populated when ProjectReferences are present

那年仲夏 提交于 2019-12-05 09:41:48
I'm loading in a solution in the MSBuildWorkspace: var msWorkspace = MSBuildWorkspace.Create(); var solution = msWorkspace.OpenSolutionAsync(solutionPath).Result; Projects without ProjectReferences show all MetadataReferences, including mscorlib. Projects with ProjectReferences have an empty collection of MetadataReferences. As compilation works, I guess the compiler platform for some reason is not populating this collection, and I'm wondering why? If I remove the ProjectReferences, the MetadataReferences collection gets populated correctly. EDIT: Diagnostics contains errors for missing

Can Roslyn be installed without Visual Studio?

纵然是瞬间 提交于 2019-12-05 08:11:10
The Roslyn end-user preview is a VSIX (Visual Studio extension), but it replaces the compilers in the system .NET Framework installation, such that involving csc.exe from the command-line will begin using Roslyn. Is it possible to install the Roslyn csc.exe on a computer without Visual Studio installed? How? (Yes, Roslyn works with Visual Studio 2013 Express, so licensing is not an issue. But disk space IS. Even the Express edition has a very large footprint compared to say SharpDevelop.) Jason Malinowski Take a look at the CompilerPackage sources to see how we install the compiler on your

How to use a Roslyn scripting submission as an assembly in other Roslyn compilations

断了今生、忘了曾经 提交于 2019-12-05 07:08:11
I'd like to reuse a script as a dynamic assembly in another non-scripting Roslyn compilation, but I can't for the life of me figure out how to make that work. For example, say a I create a script the normal way and then emit the script as an assembly to a byte stream using something like: var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); var compilation = script.GetCompilation().WithOptions(compilationOptions); using (var ms = new MemoryStream()) { EmitResult result = compilation.Emit(ms); ms.Seek(0, SeekOrigin.Begin); assembly = Assembly.Load(ms

StackExchange.Precompilation - How can I unit test precompilation diagnostics?

主宰稳场 提交于 2019-12-05 06:55:21
Background I'm using StackExchange.Precompilation to implement aspect-oriented programming in C#. See my repository on GitHub. The basic idea is that client code will be able to place custom attributes on members, and the precompiler will perform syntax transformations on any members with those attributes. A simple example is the NonNullAttribute I created. When NonNullAttribute is placed on a parameter p , the precompiler will insert if (Object.Equals(p, null)) throw new ArgumentNullException(nameof(p)); at the beginning of the method body. Diagnostics are awesome... I would like to make it

New C# 6 object initializer syntax?

依然范特西╮ 提交于 2019-12-05 06:53:26
I just noticed that the following is possible in C# written in Visual Studio 2015, but I've never seen it before: public class X { public int A { get; set; } public Y B { get; set; } } public class Y { public int C {get; set; } } public void Foo() { var x = new X { A = 1, B = { C = 3 } }; } My expectation was for Foo to have to be implemented like this: public void Foo() { var x = new X { A = 1, B = new Y { C = 3 } }; } Note that there is no need to call new Y . Is this new in C# 6? I haven't seen any mention of this in the release notes , so maybe it's always been there? You will get a

Why does the IL set this value twice?

淺唱寂寞╮ 提交于 2019-12-05 05:38:13
I was trying around a bit with Try Roslyn when I entered this piece of code: using System; using System.Linq; using System.Collections.Generic; using Microsoft.CSharp; public class C { public C() { x = 4; } public int x { get; } = 5; } And it gave me back this code: using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Security; using System.Security.Permissions; [assembly: AssemblyVersion("0.0.0.0")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations |

How do I programmatically add an assembly reference to a project?

喜夏-厌秋 提交于 2019-12-05 05:26:39
I have been trying to use Roslyn to parse a solution file and programmatically add a custom assembly reference to each project in the solution. I tried using the following code snippet to do the same: //The name of the DLL is customLib.dll var reference = MetadataReference.CreateAssemblyReference("customLib"); project = project.AddMetadataReference(reference); However, it encounters a FileNotFoundException while creating the MetadataReference. So, my question is : How do I specify the path at which Roslyn needs to check for the specified dll ? Thanks. MetadataReference.CreateAssemblyReference

Built-in C#/VB.Net editor with intellisense - Roslyn, VSTA, or something else?

▼魔方 西西 提交于 2019-12-05 04:52:15
I need to provide scripting capabilities within my application, allowing customers to extend its functionality using our object model. I was hoping to offer some kind of integrated C#/VB.Net editor with intellisense, but after looking at products like AvalonEdit and ScintillaNet, they don't appear to provide true code-completion, just an API where you can provide your own list of items to appear in the popup autocomplete list. I was therefore wondering if Roslyn provided any such features? From the tutorials and examples I've come across, it appears that Roslyn is really just a compiler

How to Perform Reflection Operations using Roslyn

江枫思渺然 提交于 2019-12-05 03:30:46
问题 I would like to perform reflection style operations on the following class using Roslyn: public abstract class MyBaseClass { public bool Method1() { return true; } public bool Method2() { return true; } public void Method3() { } } Basically I want to do this, but with Roslyn: BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; MethodInfo[] mBaseClassMethods = typeof(MyBaseClass).GetMethods(flags); foreach (MethodInfo mi in mBaseClassMethods) { if (mi.GetParameters().Length == 0

Avoid VBCSCompiler perf hit on Roslyn powered ASP.NET Razor MVC views?

北慕城南 提交于 2019-12-05 01:40:43
问题 In order to support C# 6 in our Razor views on MVC5, we turned on the Roslyn compiler platform via web.config: <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> </compilers> </system.codedom>