dotnet / dotnet/roslyn

Compiler ignores preprocessor directives surrounding MSBuild directives in file-based apps

Open
#85,203 8 comments 0 reactions 1 assignee Claimed by @jjonescz View on GitHub
Area-Compilers Feature - Run File
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

A classic case of "is this a bug, or is this a feature"?

I vote that this is a bug.

Seeing that the compiler wouldn't be invoked before the project file is available, debatable whether the minimal repro should generate an MSBuild warning, or work as written.

**Version Used**:
```
error CS8304: Compiler version: '5.9.0-1.26379.115 (14fbf8d5271c98133561eb55185fdb05b286f578)'. Language version: 14.0.
```

**Steps to Reproduce**:

1. Compile the minimal repro below
2. Observe that it compiles and runs

A minimal repro, with source-code provided, is ideal. Most compiler/language issues can be distilled into a snippet that can be pasted into [.NET Lab](https://lab.razor.fyi/#csharp).

```CS
#if false
#:package System.Threading.RateLimiting@10.0.11
#endif
using System.Threading.RateLimiting;
Console.WriteLine("Hello World!");
```

**Diagnostic Id**:

If this is a report about a bug in an analyzer, please include the diagnostic ID and message if possible (e.g. `"IDE0030: Use coalesce expression"`).

**Expected Behavior**:

```CS
#if false
//#:package System.Threading.RateLimiting@10.0.11
#endif
using System.Threading.RateLimiting;
Console.WriteLine("Hello World!");
```

```PS
PS C:\> dotnet csciffalse.cs
C:\csciffalse.cs(4,24): error CS0234: The type or namespace name 'RateLimiting' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)
```

**Actual Behavior**:

```PS
PS C:\> dotnet csciffalse.cs
Hello World!

PS C:\>
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.