roslyn

Roslyn - compiling simple class: “The type or namespace name 'string' could not be found…”

北战南征 提交于 2020-12-13 18:35:23
问题 I'm using the Roslyn API to generate and compile a class. The generated class looks like this: namespace MyCompany.Product { public class TestClass { public void Configure(string id) { } } } However, when i come to compile it, the Emit(ted) result gives: error CS0246: The type or namespace name 'string' could not be found (are you missing a using directive or an assembly reference?) Here is the method which performs the compile: private static readonly IEnumerable<string> DefaultNamespaces =

Roslyn - compiling simple class: “The type or namespace name 'string' could not be found…”

雨燕双飞 提交于 2020-12-13 18:32:51
问题 I'm using the Roslyn API to generate and compile a class. The generated class looks like this: namespace MyCompany.Product { public class TestClass { public void Configure(string id) { } } } However, when i come to compile it, the Emit(ted) result gives: error CS0246: The type or namespace name 'string' could not be found (are you missing a using directive or an assembly reference?) Here is the method which performs the compile: private static readonly IEnumerable<string> DefaultNamespaces =

Roslyn dynamic class generation issue

为君一笑 提交于 2020-12-13 04:06:51
问题 So I am trying to create a dynamic type (at runtime) using Roslyn. The entire back story to this requirement is too long to go into. I do however need to create a new type which has x many properties, where I am trying to feed in the property names and initial values from a Dictionary Here is the relevant code private void CreateAssembly(Dictionary<string, string> propertiesToEmit) { if (ourAssembly == null) { StringBuilder sb = new StringBuilder(); sb.AppendLine("using System;"); sb

Roslyn dynamic class generation issue

◇◆丶佛笑我妖孽 提交于 2020-12-13 04:05:50
问题 So I am trying to create a dynamic type (at runtime) using Roslyn. The entire back story to this requirement is too long to go into. I do however need to create a new type which has x many properties, where I am trying to feed in the property names and initial values from a Dictionary Here is the relevant code private void CreateAssembly(Dictionary<string, string> propertiesToEmit) { if (ourAssembly == null) { StringBuilder sb = new StringBuilder(); sb.AppendLine("using System;"); sb

CSC: error CS0041: Unexpected error writing debug information — 'Operation is not supported on this platform.'

南楼画角 提交于 2020-11-30 11:08:23
问题 Just downloaded Visual Studio Professional for Mac and I cannot seem to build anything as I always get the same error: /Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/xbuild/14.0/bin/Microsoft.CSharp.targets (CoreCompile target) -> CSC: error CS0041: Unexpected error writing debug information -- 'Operation is not supported on this platform.' 19 Warning(s) 1 Error(s) Not sure what to change on my project to get things to compile. 回答1: I was able to work around this problem two ways:

CSC: error CS0041: Unexpected error writing debug information — 'Operation is not supported on this platform.'

你说的曾经没有我的故事 提交于 2020-11-30 11:04:55
问题 Just downloaded Visual Studio Professional for Mac and I cannot seem to build anything as I always get the same error: /Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/xbuild/14.0/bin/Microsoft.CSharp.targets (CoreCompile target) -> CSC: error CS0041: Unexpected error writing debug information -- 'Operation is not supported on this platform.' 19 Warning(s) 1 Error(s) Not sure what to change on my project to get things to compile. 回答1: I was able to work around this problem two ways:

CSC: error CS0041: Unexpected error writing debug information — 'Operation is not supported on this platform.'

一世执手 提交于 2020-11-30 11:04:35
问题 Just downloaded Visual Studio Professional for Mac and I cannot seem to build anything as I always get the same error: /Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/xbuild/14.0/bin/Microsoft.CSharp.targets (CoreCompile target) -> CSC: error CS0041: Unexpected error writing debug information -- 'Operation is not supported on this platform.' 19 Warning(s) 1 Error(s) Not sure what to change on my project to get things to compile. 回答1: I was able to work around this problem two ways:

CSC: error CS0041: Unexpected error writing debug information — 'Operation is not supported on this platform.'

本秂侑毒 提交于 2020-11-30 11:04:06
问题 Just downloaded Visual Studio Professional for Mac and I cannot seem to build anything as I always get the same error: /Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/xbuild/14.0/bin/Microsoft.CSharp.targets (CoreCompile target) -> CSC: error CS0041: Unexpected error writing debug information -- 'Operation is not supported on this platform.' 19 Warning(s) 1 Error(s) Not sure what to change on my project to get things to compile. 回答1: I was able to work around this problem two ways:

微软是如何重写C#编译器并使它开源的

﹥>﹥吖頭↗ 提交于 2020-10-28 19:24:19
译者:王亮 作者:Mads Torgersen (C# Language PM at Microsoft) 原文: http://t.cn/EPOG96O 译者的一些话: 看了大家的评论,有园友说我翻译的不好,这我是认同的。我必须得承认,我翻译的确实很生硬,这点我自己也能很明显得感觉得到。以前没有翻译过文章,这个国庆期间翻译了几篇,发现还是挺吃力的,容易理解的英文句子组合成中文总觉得别扭,我的经验和水平还有待很大的提高。 非常真诚地感谢大家给出的反馈,这是对我最好的鞭策,以后一定努力给大家带来优质的内容。 Roslyn 是 C# 和 Visual Basic.NET 的开源编译器的代号。以下是它如何在过去十年微软公司最暗淡的环境中开始,并成为开源、跨平台、公共语言引擎的,这一切都是为了 C#(和 VB,下文同)。 当我在 2005 年加入微软的时候,第一次谈话就开始讨论了关于 Roslyn 将来会是什么样子——那时还是 .NET 2.0 发布之前。那次谈话是关于用 C# 重写 C#。这是编程语言的一种常规做法,是语言成熟一个标志证明。但是还有一个更实际和重要的动机:我们作为 C# 的创造者并不是用 C# 编程,而是用 C++ 编程!每天用 C# 工作让你对 C# 有不同的看法:这是“dogfooding”的力量。(译注:dogfooding 是内部试用或内部测试的意思。)

C#9.0 终于来了,您还学的动吗? 带上VS一起解读吧!

China☆狼群 提交于 2020-10-27 17:45:53
一:背景 1. 讲故事 好消息, .NET 5.0 终于在2020年6月10日发布了第五个预览版,眼尖的同学一定看到了在这个版本中终于支持了 C# 9.0 ,此处有掌声,太好了!!! .Net5官方链接 可以看到目前的C#9还是预览版,实现了一部分新语法供开发者提前尝鲜,从github的roslyn仓库上可以看到目前准备实现 17 个新特性,现阶段已经实现了 8 个,其中的 In Progress 表示正在开发中。 新特性预览 2. 安装必备 下载最新的 net5 sdk 吧: dotnet-sdk-5.0.100-preview.5.20279.10-win-x64.exe 下载最新的 visual studio 2019 preview 2 找好你自己的vs版本类型哦。。。 二:新特性研究 1. Target-typed new 这个取名一定要留给学易经的大师傅,没见过世面的我不敢造次,取得不佳影响时运,所谓 运去金成铁, 时来铁似金 ,不过大概意思就是说直接new你定义的局部变量的类型,用 issues 中总结的话就是: Summary: Allow Point p = new (x, y); Shipped in preview in 16.7p1. 接下来就是全部代码,看看 使用前 和 使用后 的具体差别。 class Program { static void Main