roslyn-linq-rewrite icon indicating copy to clipboard operation
roslyn-linq-rewrite copied to clipboard

How to add to regular C# project

Open ProductiveRage opened this issue 8 years ago • 10 comments

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)?

ProductiveRage avatar Sep 20 '16 20:09 ProductiveRage

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.

antiufo avatar Sep 20 '16 20:09 antiufo

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.

HalfVoxel avatar Sep 21 '16 08:09 HalfVoxel

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.

jspraul avatar Sep 21 '16 16:09 jspraul

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.

antiufo avatar Sep 21 '16 20:09 antiufo

That's great! I'll try it tomorrow. Thanks!

ProductiveRage avatar Sep 21 '16 20:09 ProductiveRage

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!

L0w3nd avatar Sep 29 '16 22:09 L0w3nd

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...
...

antiufo avatar Sep 30 '16 05:09 antiufo

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(IEnumerable1 originalArguments, BuildPaths buildPaths, TextWriter textWriter) at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run(IEnumerable1 arguments, IEnumerable1 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(List1 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, IEnumerable1 prologue, IEnumerable1 epilogue, ExpressionSyntax collection, List1 chain, AggregationDelegate k, Boolean noaggregation, IEnumerable1 additionalParameters) at Shaman.Roslyn.LinqRewrite.LinqRewriter.TryRewrite(String aggregationMethod, ExpressionSyntax collection, ITypeSymbol semanticReturnType, List1 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](SyntaxList1 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](SyntaxList1 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](SyntaxList1 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(IEnumerable1 originalArguments, BuildPaths buildPaths, TextWriter textWriter) at Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run(IEnumerable1 arguments, IEnumerable1 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.

L0w3nd avatar Sep 30 '16 20:09 L0w3nd

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",
        };

L0w3nd avatar Sep 30 '16 22:09 L0w3nd

Please make it support Unity3D. Most mobile game developers use Unity3D. It will be of great help to us.

1987skywalker avatar Apr 01 '17 12:04 1987skywalker