roslyn

How to load an existing assembly with Roslyn, transform it and generate new .cs files

非 Y 不嫁゛ 提交于 2021-02-19 04:47:07
问题 It seems like the documentation around Roslyn is a bit lacking? I am not able to find good comprehensive documentation. What I am trying to do essentially is copy the public surface of an existing API (.dll) into a new assembly (need to create source code .cs files!) and at the same time make a variety of tranformations to the resulting code (think making wrapper classes). Would really appreciate any help in how I can use Rolsyn to load the initial SyntaxTree from an existing assembly and how

How to install Roslyn (for use in source-code-modification)?

家住魔仙堡 提交于 2021-02-18 03:26:53
问题 I don't want to install the compiler - as far as I know it's already installed. (I'm using Visual Studio 2015). I don't want the source code. I just want to be able to do some simple code changing like this question asks about. What I've found is mainly github which doesn't seem clear. And other sources seem to be quite outdated. Is there something there that I'm overlooking? So - How do I get the tools I need for source-code-modifying using Roslyn? 回答1: This is sort of a tough question to

How to install Roslyn (for use in source-code-modification)?

心已入冬 提交于 2021-02-18 03:26:49
问题 I don't want to install the compiler - as far as I know it's already installed. (I'm using Visual Studio 2015). I don't want the source code. I just want to be able to do some simple code changing like this question asks about. What I've found is mainly github which doesn't seem clear. And other sources seem to be quite outdated. Is there something there that I'm overlooking? So - How do I get the tools I need for source-code-modifying using Roslyn? 回答1: This is sort of a tough question to

Roslyn – custom build error extension

半世苍凉 提交于 2021-02-17 06:21:27
问题 Is currently a way to extend Roslyn compilation and add some custom rule set that will break a build and show in ErrorList of VisualStudio? I search StackOverflow but there is no answer that works - maybe recently something came up in this topic or maybe there is other way to do this without roslyn? 回答1: Roslyn – custom build error extension Just like Slaks and JoshVarty said, this is an analyzer feature. To create your custom Roslyn analyzer rule, you can check this MS tutorial: C# and

How to set assembly version, culture and public key token while compiling with Roslyn?

不羁的心 提交于 2021-02-16 19:22:27
问题 I'm using Roslyn to emit a CSharpCompilation object in Visual Studio to a file. The DLL that is generated does not contain any assembly info other than the assembly metadata, and I'd like to add the version and sign it if possible. How can these be done with Roslyn? 回答1: You need to include source code which sets the Assembly* attributes just like in the VS C# project templates. If you have done that, the .NET version info is set. You can read that information with Reflection or tools like

How to set assembly version, culture and public key token while compiling with Roslyn?

爷,独闯天下 提交于 2021-02-16 19:22:17
问题 I'm using Roslyn to emit a CSharpCompilation object in Visual Studio to a file. The DLL that is generated does not contain any assembly info other than the assembly metadata, and I'd like to add the version and sign it if possible. How can these be done with Roslyn? 回答1: You need to include source code which sets the Assembly* attributes just like in the VS C# project templates. If you have done that, the .NET version info is set. You can read that information with Reflection or tools like

roslyn dependenceis MissingMethodException

ε祈祈猫儿з 提交于 2021-02-11 08:32:40
问题 After upgrading the dependencies in project roslyn compiler started to throw missing method exception in the following code that before update worked: CSharpCompilation compilation = CreateCompilation(templateId, syntaxTrees, metadataReferences); EmitResult compileResult; generatedAssembly = string.Empty; using (var stream = new MemoryStream()) { compileResult = compilation.Emit(stream); Now its throwing MissingMethod exception: System.MissingMethodException Method not found: 'System

roslyn dependenceis MissingMethodException

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-11 08:31:48
问题 After upgrading the dependencies in project roslyn compiler started to throw missing method exception in the following code that before update worked: CSharpCompilation compilation = CreateCompilation(templateId, syntaxTrees, metadataReferences); EmitResult compileResult; generatedAssembly = string.Empty; using (var stream = new MemoryStream()) { compileResult = compilation.Emit(stream); Now its throwing MissingMethod exception: System.MissingMethodException Method not found: 'System

Is it possible to run tests on an in-memory assembly?

吃可爱长大的小学妹 提交于 2021-02-10 14:25:42
问题 I am currently building a mutationtest framework for .NET. I want to run the unit tests from a project on an in-memory assembly. This way the mutated assembly won't have to be writen to disk and my framework will be faster to use. Using the Roslyn compiler in .Net Core 2.0 I mutate (change) the syntaxtree and compile it into an in-memory assembly like this: Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(ms); Does anyone know of a way to unit test this assembly without writing