简体   繁体   中英

How to raise Visual Studio errors (that break the build process) from a VS extension?

I'm developing a Visual Studio Extension and I need to show errors in the VS Error List to the user. I want these errors to prevent/break the building/running of the solution, ie, something like this. How can I achieve this?

I've tried two approaches but both of them only show errors, they do note break/prevent building of the solution:

  1. Adapt the ErrorList VSSDK Example project such that errors instead of messages are raised. Errors are shown properly but building is still possible.
  2. Use the ErrorListProvider as described here . Same issue as 1.

I've also looked a bit at using Diagnostics but you need ReportDiagnostic which seems to be related to code Analyzers specifically.

What you actually need is a build error. For this, you should use Roslyn technology. See this similar issue .

Reason why the error occurs in Error list but can't break the build:

According to this similar issue , it's by design that the rules from Nuget can break the build in VS IDE while rules from VS extension can't. So we can use the MSBuild magic in nuget to break the build if we need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM