Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add to regular C# project #3

Open
ProductiveRage opened this issue Sep 20, 2016 · 10 comments
Open

How to add to regular C# project #3

ProductiveRage opened this issue Sep 20, 2016 · 10 comments

Comments

@ProductiveRage
Copy link

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

@antiufo
Copy link
Owner

antiufo commented Sep 20, 2016

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.

@HalfVoxel
Copy link

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.

@jspraul
Copy link

jspraul commented Sep 21, 2016

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.

@antiufo
Copy link
Owner

antiufo commented Sep 21, 2016

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.

@ProductiveRage
Copy link
Author

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

@L0w3nd
Copy link

L0w3nd commented Sep 29, 2016

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 dotnet/roslyn#4376

This builds fine in VS, so I'll let you know if I can debug the issue.

Thanks!

@antiufo
Copy link
Owner

antiufo commented Sep 30, 2016

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

@L0w3nd
Copy link

L0w3nd commented Sep 30, 2016

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

L0w3nd commented Sep 30, 2016

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

@1987skywalker
Copy link

1987skywalker commented Apr 1, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants