0

Is there a csproj target or property that I can use to differentiate the automatic compilation that Roslyn LSP runs to give me diagnostics on VSCode from actual explicit build compilation?

I need to have different csproj elements when running on IDE vs when building. But I don't want to change the build (e.g. by adding extra MSBuild properties via command-line).

Is there some MSBuild target like a "pre-lint" or a property like a "IDE=true" which is already automatically added/called by Roslyn or Omnisharp only when linting on the IDE (i.e. when getting errors/warnings squiggles automatically when typing, not when running a build task)?

8
  • 1
    There is some MSBuild properties that can be used to distinguish, but since you mentioned analyzers there's some caveats to even getting to that. That said, you can you offer a bit more insight into why you are needing different behaviors here? This feels a bit like an XY problem and you might be on the right track but also might be going the wrong way. Commented Sep 8, 2023 at 18:50
  • @JasonMalinowski I was basically trying to workaround a bug in the VSCode C# extension where it doesn't recognize generated sources properly, which gives me errors in the IDE (but not when building). Explicitly including the generated sources as compile input solves it, but I'd have to do that conditionally, so it works both in IDE and when building. Turns out I was able to use a setting so it uses Omnisharp instead of Roslyn (which doesn't have that bug). Still it's an interesting question I think, and it could be useful in general to be able to do that for other potential use cases. Commented Sep 8, 2023 at 22:30
  • There is no "pre-lint" or "lint" target. In the "build", the analyzers are run are part of the csc task which invokes the C# compiler. Although it may be reading the project file, the editor is not running MSBuild to produce the "errors/warnings squiggles". Commented Sep 9, 2023 at 2:25
  • Are you saying that you have auto-generated source files that you don't compile? Is that correct? If you explicitly add the files to the project as items in the none item group, instead of the compile item group, does that resolve the issue? Commented Sep 9, 2023 at 2:30
  • 1
    Yeah, we need to just fix the bug properly here; I'm hoping to look at this in the next week or two. Commented Sep 19, 2023 at 19:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.