-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Problems with referencing Microsoft.CodeAnalysis.Workspaces from an analyzer #7929
Comments
|
|
True, but it will hurt performance for a large project to format every document every time.The StyleCopAnalyzers project have implemented very targeted rules for formatting, but perhaps there is an easier way to do what you want. Are you trying to detect if the user is not using some specified formatting options? You could just write a Visual Studio extension that enforces a set of options, or write a commandline tool that uses the AdHocWorkspace.
The compiler only knows about things that happen at a project level and analyzers can only know what the compiler knows. We've had some discussions around designing an API that could allow you to analyze a workspace, but we haven't figured out a way to do it that wouldn't hurt performance. |
There are two problems with that. First, my practice shows that sometimes enforcing VS formatting options is not enough. Unfortunately, VS auto-formatting experience is not perfect and sometimes leaves blocks of code formatted incorrectly until user re-types the closing brace or reformats the document manually, which is something people tend to forget to do all the time. And second, extension can't be enforced on user by the project referencing a nuget package, thus making it useless for hypothetical open source scenarios.
This solution basically shares the same problems. It's theoretically possible to distribute this tool as a nuget package that edits the project to insert a pre-build step that launches the tool, but it sounds a lot more awkward than just running the analyzer during the build (I'm basically re-inventing the way you're running analyzers during build). And the VS experience would obviously be worse than with a proper analyzer.
Will it really be worse than detecting all the possible formatting issues manually? I'll need to rewrite a lot of
But I don't really want to analyze the whole workspace (at least not in this topic ;)). I'm perfectly fine with doing things at a project level; actually, for this analyzer to work there's no need for anything higher than a syntax tree. What does |
Looking over the |
I've opened #8268 to discuss the suggested API changes, so I'm closing this one. |
I have an analyzer that uses
Formatter
class fromMicrosoft.CodeAnalysis.Workspaces
that's installed into a project via a nuget package. Even though it works when editing code in Visual studio (I get the warning squiggles and the associated code fix is triggered byCtrl+.
), whenever I build the project, I get the following warning:First I thought it was a version mismatch issue that occurred after Update 1, but trying 3 different stable package versions (1.0.0, 1.1.1 and 1.1.0) didn't change anything.
Then I tried including
Microsoft.CodeAnalysis.Workspaces
dll into the nuget package and it seemed to have some effect (the dll the warning was about changed to something else, one of dependencies ofMicrosoft.CodeAnalysis.Workspaces
, I guess), but it screwed up the code fix (VS started throwing 'One or more error occurred' pop-up onCtrl+.
).Am I doing something wrong here or is it an actual bug? And how does the analyzer work if VS claims it can't load the assembly it requires?
The text was updated successfully, but these errors were encountered: