dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.96k stars 4.02k forks source link

Different compilation errors between the command-line and Visual Studio #17409

Open davkean opened 7 years ago

davkean commented 7 years ago

From @eyalsk on February 25, 2017 22:53

Version Used: Microsoft Visual Studio Community 2017 RC (15.0.26206.0 D15REL)

When I compile through the command-line I get the expected errors:

Completion\Providers\AbstractSymbolCompletionProvider.cs(339,53): error CS1929: 'HashSet<(ISymbol, CompletionItemRules)>' does not contain a definition for 'Except' and the best extension method overload 'Para
llelEnumerable.Except<(ISymbol symbol, CompletionItemRules)>(ParallelQuery<(ISymbol symbol, CompletionItemRules)>, ParallelQuery<(ISymbol symbol, CompletionItemRules)>, IEqualityComparer<(ISymbol symbol, Compl
etionItemRules)>)' requires a receiver of type 'ParallelQuery<(ISymbol symbol, CompletionItemRules)>' [D:\Projects\roslyn\src\Features\Core\Portable\Features.csproj]
Completion\Providers\AbstractSymbolCompletionProvider.cs(339,76): error CS1503: Argument 2: cannot convert from 'System.Collections.Immutable.ImmutableArray<(Microsoft.CodeAnalysis.ISymbol symbol, Microsoft.Co
deAnalysis.Completion.CompletionItemRules rules)>' to 'System.Linq.ParallelQuery<(Microsoft.CodeAnalysis.ISymbol symbol, Microsoft.CodeAnalysis.Completion.CompletionItemRules)>' [D:\Projects\roslyn\src\Feature
s\Core\Portable\Features.csproj]
Completion\Providers\AbstractSymbolCompletionProvider.cs(340,47): error CS1579: foreach statement cannot operate on variables of type '?' because '?' does not contain a public definition for 'GetEnumerator' [D
:\Projects\roslyn\src\Features\Core\Portable\Features.csproj]

But when I compile through Visual Studio I get loads of additional errors that are unrelated to the problems I need to fix in the code, here are few examples of the errors I got:

Severity    Code    Description Project File    Line    Suppression State
Error   BC2017  could not find library 'D:\Projects\roslyn\Binaries\Debug\Dlls\BasicFeatures\Microsoft.CodeAnalysis.VisualBasic.Features.dll'   BasicInteractiveEditorFeatures  D:\Projects\roslyn\src\Interactive\EditorFeatures\VisualBasic\vbc   1   Active
Severity    Code    Description Project File    Line    Suppression State
Error   CS0006  Metadata file 'D:\Projects\roslyn\Binaries\Debug\Dlls\CSharpEditorFeatures\Microsoft.CodeAnalysis.CSharp.EditorFeatures.dll' could not be found ServicesTestUtilities   D:\Projects\roslyn\src\EditorFeatures\TestUtilities\CSC 1   Active
Severity    Code    Description Project File    Line    Suppression State
Error       The tag 'AbstractOptionPageControl' does not exist in XML namespace 'clr-namespace:Microsoft.VisualStudio.LanguageServices.Implementation.Options;assembly=Microsoft.VisualStudio.LanguageServices.Implementation'. Line 2 Position 5.  CSharpVisualStudio  D:\Projects\roslyn\src\VisualStudio\CSharp\Impl\Options\AdvancedOptionPageControl.xaml  2   

Related PR.

Just a note, I've already fixed the compilation errors but this can get really frustrating because when it happens, the error list window doesn't show the actual errors and you get no squiggles so you don't even know what to fix unless you compile it through the command-line.

Copied from original issue: dotnet/roslyn-project-system#1625

CyrusNajmabadi commented 7 years ago

Is this not the issue where building in VS doesn't stop when it hits an error? Thus leading to much cascading of errors? If so, who is the best team to address this? AFAIK, Roslyn doesn't control that behavior, it's something baked into VS.

davkean commented 7 years ago

Apart from the last error (which is occurring because the XAML page is open) the other errors are all because of Roslyn.

CyrusNajmabadi commented 7 years ago

But the last errors are happening because we're being asked to compile projects whose dependencies did not build. If you tried to compile the projects form the command line, but didn't include those dependencies, wouldn't you get the same errors? You just don't normally get this from the command line because the compiling of a dependency chain stops when one of hte dependent projects fails to build.

CyrusNajmabadi commented 7 years ago

Here's a simple example. I made a basic solution with a console app and a class library. I made the console app reference the class library. I then added an error to the class library. when i try to build from VS i get:

1>------ Build started: Project: CSharpClassLibrary5, Configuration: Debug Any CPU ------
1>c:\users\cyrusn\documents\visual studio 2017\Projects\CSharpClassLibrary5\CSharpClassLibrary5\Class1.cs(13,13,13,19): error CS0127: Since 'Class1.Foo()' returns void, a return keyword must not be followed by an object expression
2>------ Build started: Project: CSharpConsoleApp1, Configuration: Debug Any CPU ------
2>CSC : error CS0006: Metadata file 'c:\users\cyrusn\documents\visual studio 2017\Projects\CSharpClassLibrary5\CSharpClassLibrary5\bin\Debug\CSharpClassLibrary5.dll' could not be found
========== Build: 0 succeeded, 2 failed, 0 up-to-date, 0 skipped ==========

Note how VS decided to build the console app, even though the dependencies didn't build.

However, when i do this from the command line, i only get:

Class1.cs(13,13): error CS0127: Since 'Class1.Foo()' returns void, a return keyword must not be followed by an object expression [c:\Users\cyrusn\Documents\Visual Studio 2017\Projects\CSharpClassLibrary5\CSharpClassLibrary5\CSharpClassLibrary5.csproj]
Done Building Project "c:\Users\cyrusn\Documents\Visual Studio 2017\Projects\CSharpClassLibrary5\CSharpClassLibrary5\CSharpClassLibrary5.csproj" (default targets) -- FAILED.

Done Building Project "c:\Users\cyrusn\Documents\Visual Studio 2017\Projects\CSharpClassLibrary5\CSharpClassLibrary5.sln" (default targets) -- FAILED.

msbuild knows to not even bother with the dependent projects.

I don't know why we even get to:

2>------ Build started: Project: CSharpConsoleApp1, Configuration: Debug Any CPU ------

If the prereqs failed, then it feels like we shouldn't even bother calling to the compiler to try to build this project. If we do, we'll of course get an error, just like

CyrusNajmabadi commented 7 years ago

Note: there's an extension to help out here: https://marketplace.visualstudio.com/items?itemName=EinarEgilsson.StopOnFirstBuildError

But it seems like it would be good if VS's build system just behaved the same way as MSBuild.