roslyn

Can not delete \bin\roslyn\VBCSCompiler.exe - Access is denied

落爺英雄遲暮 提交于 2019-12-03 02:33:02
问题 I am facing a strange issue from roslyn compiler. Sometimes when I build the solution I face a strange issue in error list which does not let me build the solution. Here is the error: Severity Code Description Project File Line Suppression State Error Unable to copy file "D:\Sealogical New Website\SealogicalWebsite\packages\Microsoft.Net.Compilers.1.0.0\tools\csc.exe" to "bin\roslyn\csc.exe". Access to the path 'bin\roslyn\csc.exe' is denied. SealogicalWebsite Severity Code Description

How to modify code before compilation?

浪尽此生 提交于 2019-12-03 01:28:42
问题 Using Roslyn, I would like to modify my C# code before the actual compilation. For now, I will just need something like: [MyAnotatedMethod] public void MyMethod() { // method-body } And based on the annotation, I would like to inject some code at the beginning of the method, and at the end of the method. I'm aware of PostSharp, but that's not what I would like. Is this possible to do with Roslyn? And if yes, could you give me an example? 回答1: Here is a quick and dirty way of doing what you

未能加载文件或程序集“System.Collections.Immutable”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。

匿名 (未验证) 提交于 2019-12-03 00:09:02
因为升级ABP.NET,导致原来老项目的System.Collections.Immutable引用报错。 步骤: 1.将引用的System.Collections.Immutable全部换成\packages\System.Collections.Immutable.1.2.0\lib\portable-net45+win8+wp8+wpa81下的,而不是\packages\Microsoft.Net.Compilers.1.3.2\tools下的(不知道为什么,明明引用的是System.Collections.Immutable.1.2.0文件夹下的,但查看属性显示的路径总是Microsoft.Net.Compilers.1.3.2文件夹下,可以先把Microsoft.Net.Compilers.1.3.2文件夹放到别的地方,之后再看需不需要移回来); 2.这时候报的错误会变成找不到\roslyn\csc.exe,出现这个问题可能是因为VS没有把Roslyn的编译器正确地放到网站Bin文件夹的roslyn文件夹中,将\packages\Microsoft.Net.Compilers.1.3.2\tools\bin\roslyn下的文件都复制到l\bin\roslyn下面; 可以参考: https://www.cnblogs.com/lizhanglong/p/6894361

Getting interface implementations in referenced assemblies with Roslyn

孤街醉人 提交于 2019-12-02 23:06:33
I'd like to bypass some classical assembly scanning techniques in a framework I am developing. So, say I've defined the following contract: public interface IModule { } This exists in say Contracts.dll . Now, if I want to discover all implementations of this interface, we would probably do something similar to the following: public IEnumerable<IModule> DiscoverModules() { var contractType = typeof(IModule); var assemblies = AppDomain.Current.GetAssemblies() // Bad but will do var types = assemblies .SelectMany(a => a.GetExportedTypes) .Where(t => contractType.IsAssignableFrom(t)) .ToList();

Loading a Roslyn compiled assembly into a sandbox AppDomain

谁说我不能喝 提交于 2019-12-02 22:52:50
I've got a code-snippet that compiles a script with the script engine and I retreiv the assembly as a byte array. Now I want to load this Assembly in a Sandbox, this is what I've got: Assembly _dynamicAssembly; ScriptEngine _engine; Session _session; public string Execute(string code) { // Setup sandbox var e = new Evidence(); e.AddHostEvidence(new Zone(SecurityZone.Internet)); var ps = SecurityManager.GetStandardSandbox(e); var setup = new AppDomainSetup { ApplicationBase = Environment.CurrentDirectory }; var domain = AppDomain.CreateDomain("Sandbox", AppDomain.CurrentDomain.Evidence, setup,

Null propagation operator and extension methods

萝らか妹 提交于 2019-12-02 21:48:54
I've been looking at Visual Studio 14 CTP along with C# 6.0 and playing with the null-propagation operator. However, I couldn't find why the following code does not compile. The features are not yet documented so I'm not sure whether this is a bug or extension methods simply are not supported with the ?. operator and the error message is misleading. class C { public object Get() { return null; } } class CC { } static class CCExtensions { public static object Get(this CC c) { return null; } } class Program { static void Main(string[] args) { C c = null; var cr = c?.Get(); //this compiles (Get

C# REPL outside Visual Studio

我是研究僧i 提交于 2019-12-02 18:54:26
F# has a REPL (read–eval–print loop) F# Interactive, C:\Program Files (x86)\Microsoft F#\v4.0\Fsi.exe . I understand C# now has its own interactive REPL, as released with Roslyn . How do I open outside Visual Studio? Where is csi.exe ? C# Interactive window and csi.exe REPL were added to Visual Studio 2015 Update 1 (emphasis mine): Introducing Interactive The Interactive Window is back! The C# Interactive Window returns in Visual Studio 2015 Update 1 along with a couple other interactive treats: C# Interactive . The C# Interactive window is essentially a read-eval-print-loop (REPL) that allows

Why are there so many implementations of Object Pooling in Roslyn?

心已入冬 提交于 2019-12-02 17:29:05
The ObjectPool is a type used in the Roslyn C# compiler to reuse frequently used objects which would normally get new'ed up and garbage collected very often. This reduces the amount and size of garbage collection operations which have to happen. The Roslyn compiler seems to have a few separate pools of objects and each pool has a different size. I want to know why there are so many implementations, what the preferred implementation is and why they picked a pool size of 20, 100 or 128. 1 - SharedPools - Stores a pool of 20 objects or 100 if the BigDefault is used. This one is also strange in

How can I make my code diagnostic syntax node action work on closed files?

China☆狼群 提交于 2019-12-02 17:22:40
I'm building a set of code diagnostics using Roslyn (in VS2015 Preview). Ideally, I'd like any errors they produce to act as persistent errors, just as if I were violating a normal language rule. There are a bunch of options, but I'm having a hard time getting any of them to work consistently. I've managed to implement a rudimentary syntax node action, i.e. one registered with context.RegisterSyntaxNodeAction(AnalyzeSyntaxNode, SyntaxKind.InvocationExpression); in the Initialize method of my diagnostic class. Lo and behold, when I open up a file which violates this diagnostic (while running

Enums in lambda expressions are compiled differently; consequence of overload resolution improvements?

我怕爱的太早我们不能终老 提交于 2019-12-02 17:13:58
While trying out the Visual Studio 2015 RC, I received a run-time error on previously working code. Given the lambda (x => x.CustomerStatusID == CustomerStatuses.Active) which was passed to a function as an Expression<> , the debugger shows a difference in the expression tree. Formerly it compiled as this: .Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == 0 } But in C# 6.0 it now compiles as .Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses