Roslyn Analyzer

Open
#67 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp

Research direction

Start by reviewing issue #64 and the documented MSBuildLocator.RegisterDefaults usage to understand the failure pattern. The proposed result is a Roslyn analyzer shipped with this package that detects MSBuild API references in methods calling the locator; the issue does not name implementation files or tests.

Written by the indexing model from the issue text.

Description

There's a very common problem using Locator, which is that the natural code change to use it:

 void DoStuff()
 {
+    MSBuildLocator.RegisterDefaults();
     var project = new Microsoft.Build.Evaluation.Project(projectPath);

Doesn't work, because .NET loads all types referenced in a method before executing that method, so it tries to load MSBuild APIs before the Locator has made that possible.

#64 is one example of this but there have been a ton.

We can't fix this in the deployed code, because it won't have been loaded in time to do anything.

It might be possible, though, to create a Roslyn analyzer that ships as part of this package that checks to make sure there are no MSBuild APIs in a method that calls the locator. That would make things much easier for new users.

Dominant language
C#
Stars
262
Forks
91
Avg merge
11d 22h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/MSBuildLocator

All issues in microsoft/MSBuildLocator

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.