roslyn-linq-rewrite
roslyn-linq-rewrite copied to clipboard
How to add to regular C# project
This feels like a silly question.. but I can't work out how to try this in a standard C# project. Adding to project.json suggests that the instruction apply to .net core projects, what is the process otherwise (ie. to add to a .csproj project in Visual Studio)?
An earlier version of this project actually targeted .csproj
projects, using Microsoft.CodeAnalysis.CSharp.Workspaces
. I'll see tomorrow if I can add a console project to bring this feature back.
Similarly. I am not sure if this can even be supported, but being able to apply this to Unity3D projects would be tremendously helpful since Unity uses an old mono branch with even slower LINQ.
I'm interested in getting this to work with .NET 3.5 back here in the dark ages; a list of supported .NET versions and runtimes would be appreciated.
The latest version is now able to compile .sln
and .csproj
projects.
Usage (.sln, .csproj)
I tested it with .NET 3.5 and it works, but I haven't tried with Unity. Let me know if you encounter any problems.
That's great! I'll try it tomorrow. Thanks!
Trying it with 4.6.2 and getting this for every project in the solution: C:\Program Files (x86)\MSBuild\14.0\bin\amd64\Microsoft.CSharp.Core.targets(67,5): error MSB6006: "csc.exe" exited with code 1. [E:\git\Solution1\Solution1.DAL\Solution1.DAL.csproj]
Looks like the real error is getting swallowed similar to https://github.com/dotnet/roslyn/issues/4376
This builds fine in VS, so I'll let you know if I can debug the issue.
Thanks!
Use this to make msbuild print roslyn-linq-rewrite's stdout and get a stacktrace:
msbuild /p:CscToolPath=<directory-of-roslyn-linq-rewrite> /verbosity:detailed <path-to-csproj> /t:Rebuild
Let me know what the output is. There will be a lot of text, but what is needed is the part like this:
Microsoft (R) Visual C# Compiler version 2.0.0.60620
Copyright (C) Microsoft Corporation. All rights reserved.
LINQ Rewriter version
Rewriting LINQ to procedural code...
Some exception
at Shaman.Roslyn.Something...
...
Stacktraces from a couple 4.6.2 projects. Sorry I haven't been able to do any useful debugging yet:
Microsoft (R) Visual C# Compiler version 2.0.0.60620 Copyright (C) Microsoft Corporation. All rights reserved. LINQ Rewriter version
Rewriting LINQ to procedural code...
Rewritten 11 LINQ queries in 10 methods as procedural code.
System.ArgumentOutOfRangeException: Value must be positive.
Parameter name: count
at Microsoft.CodeAnalysis.CommonCompiler.RunCore(TextWriter consoleOutput, Object errorLogger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CommonCompiler.Run(TextWriter consoleOutput, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.<>c__DisplayClass1_0.<Run>b__0(TextWriter tw)
at Microsoft.CodeAnalysis.CommandLine.ConsoleUtil.RunWithUtf8Output[T](Func2 func) at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run(String[] args, BuildPaths buildPaths, TextWriter textWriter, IAnalyzerAssemblyLoader analyzerLoader) at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.RunLocalCompilation(String[] arguments, BuildPaths buildPaths, TextWriter textWriter) at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation(IEnumerable
1 originalArguments, BuildPaths buildPaths, TextWriter textWriter)
at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run(IEnumerable1 arguments, IEnumerable
1 extraArguments, RequestLanguage language, CompileFunc compileFunc, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
at Microsoft.CodeAnalysis.CSharp.CommandLine.ProgramLinqRewrite.MainInternal(String[] args)
at Shaman.Roslyn.LinqRewrite.Program.Main(String[] args)
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(316,9): error MSB6006: "Csc.exe" exited with code 1. [E:\git\Proj1\Proj1.DAL\Proj1.DAL.csproj]
Done executing task "Csc" -- FAILED.
Microsoft (R) Visual C# Compiler version 2.0.0.60620 Copyright (C) Microsoft Corporation. All rights reserved. LINQ Rewriter version
Rewriting LINQ to procedural code...
System.NullReferenceException: Object reference not set to an instance of an object.
at Shaman.Roslyn.LinqRewrite.LinqRewriter.<>c__DisplayClass67_2.<TryRewrite>b__4(ExpressionSyntax x)
at Shaman.Roslyn.LinqRewrite.LinqRewriter.IfNullableIsNotNull(Boolean nullable, IdentifierNameSyntax currentValue, Func2 p) at Shaman.Roslyn.LinqRewrite.LinqRewriter.<>c__DisplayClass67_2.<TryRewrite>b__3(LinqStep inv, ArgumentListSyntax arguments, ParameterSyntax param) at Shaman.Roslyn.LinqRewrite.LinqRewriter.CreateProcessingStep(List
1 chain, Int32 chainIndex, TypeSyntax itemType, String itemName, ArgumentListSyntax arguments, Boolean noAggregation)
at Shaman.Roslyn.LinqRewrite.LinqRewriter.CreateProcessingStep(List1 chain, Int32 chainIndex, TypeSyntax itemType, String itemName, ArgumentListSyntax arguments, Boolean noAggregation) at Shaman.Roslyn.LinqRewrite.LinqRewriter.RewriteAsLoop(TypeSyntax returnType, IEnumerable
1 prologue, IEnumerable1 epilogue, ExpressionSyntax collection, List
1 chain, AggregationDelegate k, Boolean noaggregation, IEnumerable1 additionalParameters) at Shaman.Roslyn.LinqRewrite.LinqRewriter.TryRewrite(String aggregationMethod, ExpressionSyntax collection, ITypeSymbol semanticReturnType, List
1 chain, InvocationExpressionSyntax node)
at Shaman.Roslyn.LinqRewrite.LinqRewriter.TryVisitInvocationExpression(InvocationExpressionSyntax node, ForEachStatementSyntax containingForEach)
at Shaman.Roslyn.LinqRewrite.LinqRewriter.TryCatchVisitInvocationExpression(InvocationExpressionSyntax node, ForEachStatementSyntax containingForEach)
at Shaman.Roslyn.LinqRewrite.LinqRewriter.VisitInvocationExpression(InvocationExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitEqualsValueClause(EqualsValueClauseSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitVariableDeclarator(VariableDeclaratorSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SeparatedSyntaxList1 list) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitVariableDeclaration(VariableDeclarationSyntax node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SyntaxList
1 list)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitBlock(BlockSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitIfStatement(IfStatementSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SyntaxList1 list) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitBlock(BlockSyntax node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitMethodDeclaration(MethodDeclarationSyntax node) at Shaman.Roslyn.LinqRewrite.LinqRewriter.VisitMethodDeclaration(MethodDeclarationSyntax node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SyntaxList
1 list)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitClassDeclaration(ClassDeclarationSyntax node)
at Shaman.Roslyn.LinqRewrite.LinqRewriter.VisitTypeDeclaration(TypeDeclarationSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SyntaxList1 list) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitNamespaceDeclaration(NamespaceDeclarationSyntax node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement[TNode](TNode node) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList[TNode](SyntaxList
1 list)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitCompilationUnit(CompilationUnitSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(SyntaxNode node)
at Microsoft.CodeAnalysis.CommonCompiler.RunCore(TextWriter consoleOutput, Object errorLogger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CommonCompiler.Run(TextWriter consoleOutput, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.<>c__DisplayClass1_0.<Run>b__0(TextWriter tw)
at Microsoft.CodeAnalysis.CommandLine.ConsoleUtil.RunWithUtf8Output[T](Func2 func) at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run(String[] args, BuildPaths buildPaths, TextWriter textWriter, IAnalyzerAssemblyLoader analyzerLoader) at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.RunLocalCompilation(String[] arguments, BuildPaths buildPaths, TextWriter textWriter) at Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation(IEnumerable
1 originalArguments, BuildPaths buildPaths, TextWriter textWriter)
at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run(IEnumerable1 arguments, IEnumerable
1 extraArguments, RequestLanguage language, CompileFunc compileFunc, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
at Microsoft.CodeAnalysis.CSharp.CommandLine.ProgramLinqRewrite.MainInternal(String[] args)
at Shaman.Roslyn.LinqRewrite.Program.Main(String[] args)
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(316,9): error MSB6006: "Csc.exe" exited with code 1. [E:\git\Proj2\Proj2\Proj2.Data.csproj]
Done executing task "Csc" -- FAILED.
At least one issue since I'm using C# 6, I needed to add my VS2015 msbuild to msbuildCandidates: @"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe".
The only msbuild I had in the list was @"%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe", which was choking on C# 6 syntax.
Still having some other problems that I'll continue to debug.
var msbuildCandidates = new[] {
@"%ProgramFiles(x86)%\Microsoft Visual Studio\VS16\MSBuild\16.0\Bin\amd64\MSBuild.exe",
@"%ProgramFiles(x86)%\Microsoft Visual Studio\VS15\MSBuild\15.0\Bin\amd64\MSBuild.exe",
@"%ProgramFiles(x86)%\Microsoft Visual Studio\VS15Preview\MSBuild\15.0\Bin\amd64\MSBuild.exe",
@"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe",
@"%ProgramFiles(x86)%\MSBuild\15.0\Bin\amd64\MSBuild.exe",
@"%ProgramFiles(x86)%\MSBuild\14.0\Bin\amd64\MSBuild.exe",
@"%ProgramFiles(x86)%\MSBuild\12.0\Bin\amd64\MSBuild.exe",
@"%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe",
};
Please make it support Unity3D. Most mobile game developers use Unity3D. It will be of great help to us.