roslyn

Build a Xamarin project via Roslyn and get the assembly

十年热恋 提交于 2019-12-11 07:38:58
问题 I need to build a Xamarin solution (the UWP project of the solution) from a console application (another solution). In windows or web applications all the referenced files are listed in the project`s file. Therefore, I am able to simply emit the project's compilation and get the assembly file. var solutionPath = "folder\solution name.sln"; var workspace = MSBuildWorkspace.Create(); var solution = await workspace.OpenSolutionAsync(solutionPath, CancellationToken); var project = solution

Derive parameter type with Roslyn

别说谁变了你拦得住时间么 提交于 2019-12-11 07:23:31
问题 I have created the following object to walk my constructor: internal class ConstructorWalker : CSharpSyntaxWalker { private string className = String.Empty; private readonly SemanticModel semanticModel; private readonly Action<string> callback; public ConstructorWalker(Document document, Action<string> callback) { this.semanticModel = document.GetSemanticModelAsync().Result; this.callback = callback; } public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node) { var

Add module as reference in Roslyn

馋奶兔 提交于 2019-12-11 07:10:45
问题 I'm trying to implement following csc command based compilation with the Roslyn Microsoft.Codeanalysis library csc /target:library /out:UserControlBase.dll UserControlBase.cs /addmodule:"c:\artifacts\MyLib.netmodule" Following is the implementation of the same with Roslyn var compilation = await project.GetCompilationAsync(); //Add Module compilation.AddReferences(ModuleMetadata.CreateFromFile(@"c:\artifacts\MyLib.netmodule").GetReference()); compilationStatus = compilation.Emit

Roslyn Project Templates VS 2015 RC

感情迁移 提交于 2019-12-11 05:19:17
问题 I can't find any Project Templates for Roslyn Extensions in the current released Visual Studio 2015 RC. Are they not available in the Release Candidate or just well hidden? I am missing the whole Roslyn folder. I have installed the Visual Studio 2015 SDK RC, do I still miss something? 回答1: They have moved to the Extensibility folder, and don't have Roslyn in the name. Instead they are named after what they actually do. Additionally, they aren't part of the base Visual Studio install. You need

Convert LINQ query to string, send to remote server to parse into an expression using Roslyn?

巧了我就是萌 提交于 2019-12-11 04:59:38
问题 I have a datasource such as IDataSource : IEnumerable<IDynamicObject> One implementation is quering pure XML-data and another is quering an SQL database. My datasources have no conrete types, and are only working against simple schema-types. In some scenarios, these datasources are instanced in the same runtime-context and other they are accessed over the network. I wasn't to be able to query my datasources with LINQ, and I'm planning on using dynamic objects to only extract and parse the

Inserting Code Between Region Trivia With Roslyn

自古美人都是妖i 提交于 2019-12-11 04:44:56
问题 How can I insert a variable declaration after a region directive in Roslyn? I'd like to be able to do something like going from this: class MyClass { #region myRegion #endregion } to this: class MyClass { #region myRegion private const string myData = "somedata"; #endregion } I can't seem to find any examples that deal with trivia in this manner. 回答1: That's quite tricky to do with a CSharpSyntaxRewriter, because both the #region <name> and #endregion end up in the same SyntaxTriviaList ,

Roslyn - how to insert variable declaration statements into beginning of script (after usings)?

半世苍凉 提交于 2019-12-11 03:28:55
问题 I'm aiming to parse C# script files supplied by users via Roslyn. Let's assume the end user provides a script like: using System; return "Hello"; I'm looking for a general way to insert a few variable initialization statements at the earliest possible location in any given script. To my understanding, that would pretty much be after the last using statement. For the sake of the example, let's assume I just need to insert "var xyz = 123;" at the earliest location. So the end result should, in

Removing and Adding content with Code Fix Provider

喜欢而已 提交于 2019-12-11 03:13:05
问题 I had that previous question which was intended to resolved the state of a local variable / parameter. It works fine, I tweak it a little bit and it looks like this now : using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using System.Collections.Immutable; using System.Linq; namespace RefactoringEssentials.CSharp.Diagnostics { [DiagnosticAnalyzer(LanguageNames.CSharp)] public class

Visual Studio 2015 Edit and Continue duplicates object fields

走远了吗. 提交于 2019-12-11 01:26:21
问题 I am experiencing weird issues during Visual Studio 2015 Community debugging a 32-bit C# application (C# 6, .NET 4.5.2) on Windows 8.1 x64. If I do a couple of Edit and Continue iterations (i.e. break execution, change something, continue), after a while I will get a weird NullReferenceException thrown for a field which cannot possibly be null. When I then hover over the this instance for the "offending" object, it turns out that there are multiple fields with the same name inside that object

Visual Studio 2017 WebSite Menu “Enable C# 6 / VB 14” fails to load Nuget Package

*爱你&永不变心* 提交于 2019-12-11 00:15:27
问题 Since a while whenever I click on the WebSite menu "Enable C# 6 / VB 14" I get an exception message saying that "Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.2" is not found in following primary resource(s): "C:\Program Files (x86)\Microsoft Web Tools\Packages" I check the folder and see that it is upgraded to version 1.0.3. (C:\Program Files (x86)\Microsoft Web Tools\Packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3) How can I bring the menu again intact in